www.久久久久|狼友网站av天堂|精品国产无码a片|一级av色欲av|91在线播放视频|亚洲无码主播在线|国产精品草久在线|明星AV网站在线|污污内射久久一区|婷婷综合视频网站

當(dāng)前位置:首頁 > 單片機 > 單片機
[導(dǎo)讀]  引言  本文介紹了如何通過MAX2990電力線通信調(diào)制解調(diào)器的I2C接口與外部EEPROM 24C04連接,并給出了相應(yīng)的固件例程。I²C總線受控于MAX2990 (主機),24C04 EEPROM為從機器件。以下框圖給出了本文示例的硬件

  引言

  本文介紹了如何通過MAX2990電力線通信調(diào)制解調(diào)器的I2C接口與外部EEPROM 24C04連接,并給出了相應(yīng)的固件例程。I²C總線受控于MAX2990 (主機),24C04 EEPROM為從機器件。以下框圖給出了本文示例的硬件配置。

  


 

  固件說明

  I²C接口初始化

  一旦使能I²C模塊,SCL和SDA必須配置成漏極開路狀態(tài),以確保I²C總線通信正常。由于I²C是GPIO端口的一個替代功能,固件必須確保SCL和SDA輸入在初始化期間禁止上拉(通過對端口控制器的輸出位寫零實現(xiàn))。

示例中,時鐘頻率為250kHz。首先需要配置MAX2990的I²C接口:

PO1_bit.Bit2 = 0; 		// Disables the GPIO function of the
PO1_bit.Bit3 = 0; 		// I2C pins

I2CCN_bit.I2CEN = 0; 	// Makes sure that I2C is disabled
			// to allow the changing of the I2C settings

I2CCN_bit.I2CMST = 1; 		// Sets the I2C engine to master mode
I2CCN_bit.I2CEA = 0; 		// 7-bit address mode
I2CCK_bit.I2CCKL = 0x40; 	// 2µs CLK-low, to define I2C frequency
I2CCK_bit.I2CCKH = 0x40; 	// 2µs CLK-high, to define I2C frequency

I2CTO = 200; 		// I2C_TIMEOUT
I2CST = 0x400; 		// Resets I2C status register

I2CCN_bit.I2CEN = 1; 		// Enables the I2C engine

寫模式

寫入24C04 EEPROM時,必須通過I²C接口寫入以下字節(jié):

  1. EEPROM的I²C總線地址(這里為0xA0)
  2. EEPROM存儲器的地址
  3. 數(shù)據(jù)字節(jié)(地址將自動遞增)

示例中試圖寫入以下字節(jié),從0x00地址開始,向EEPROM寫入:0x12、0x34、0x56、0x78和0x90。

i2c_init_write(); 	// Sets the MAX2990 I2C Engine into write mode
i2c_write(0x50); 	// 24C04 write (adr = 0b1010 000 0) = 0xA0
		// The MAX2990 I2C engine shifts the I2C address by
			// 1 bit, because it will generate the R/W bit
			// automatically

i2c_write(0x00); 	// word address location
i2c_write(0x12); 	// data1
i2c_write(0x34); 	// data2
i2c_write(0x56); 	// data3
i2c_write(0x78); 	// data4
i2c_write(0x90); 	// data5
I2C_STOP; 		// Sends I2C stop-condition


 

讀模式

讀取我們寫入EEPROM的數(shù)據(jù)時,為24C04留出足夠的寫時間非常關(guān)鍵。通常在“停止條件”后留出幾個毫秒的時間,請參考數(shù)據(jù)資料,確認您的時間設(shè)置符合IC的要求。

i2c_init_write(); 	// Sets the MAX2990 I2C engine into write mode
i2c_write(0x50); 	// 24C04 write (adr = 0b1010 000 0) = 0xA0
		// The MAX2990 I2C engine shifts the I2C address by
			// 1 bit, because it will generate the R/W bit
			// automatically

i2c_write(0x00); 	// word address location

i2c_init_read(); 	// Sets the MAX2990 I2C engine into read mode

i2c_write(0x50); 	// 24C04 read (adr = 0b1010 000 1) = 0xA1
		// The MAX2990 I2C engine shifts the I2C address by
			// 1 bit, because it will generate the R/W bit
			// automatically

unsigned char data[5]; 	// Array to store the received data
i2c_read(data[0]); // Reads 1 byte from I2C and writes it to the array
i2c_read(data[1]); // Reads 1 byte from I2C and writes it to the array
i2c_read(data[2]); // Reads 1 byte from I2C and writes it to the array
i2c_read(data[3]); // Reads 1 byte from I2C and writes it to the array
i2c_read(data[4]); // Reads 1 byte from I2C and writes it to the array
I2C_STOP; 		// Sends I2C stop-condition

現(xiàn)在,我們可以驗證一下用于EEPROM讀、寫操作的功能。

i2c_init_write(void)
i2c_init_read(void)
i2c_write(UINT8 data)
i2c_read(UINT8 *data)

 

void i2c_init_write(void)
{
I2CCN_bit.I2CMODE = 0; // I2C transmit mode
I2CCN_bit.I2CACK = 1; // Creates I2C NACK so that slave can create ACK
I2C_START; 		// Generates I2C START condition
while( I2CCN_bit.I2CSTART == 1 ); 	// Waits until the START condition
				// was put to the I2C bus
I2CST_bit.I2CSRI = 0; 		// Resets the I2C interrupt flag
}

int i2c_init_read(void)
{
I2CCN_bit.I2CMODE = 1; 	// I2C read-mode
I2CCN_bit.I2CACK = 0; 	// Creates I2C ACK after receive
I2C_START; 		// Generates I2C START condition

while( I2CCN_bit.I2CSTART == 1 ); 	// Waits until the START condition
I2CST_bit.I2CSRI = 0; 		// Resets the I2C interrupt flag
}

void i2c_write(UINT8 data)
{
I2CBUF = data; 			// Puts the data on the I2C bus
while( I2CST_bit.I2CTXI == 0 ); 	// Waits for transfer complete
I2CST_bit.I2CTXI = 0; 		// Resets the I2C transmit complete
				// interrupt flag
}

void i2c_read(UINT8 *data)
{
I2CBUF = 0xff; 	// Puts "all ones" on the I2C bus so that slave can pull
		// the bus down to generate zeros

while( !I2CST_bit.I2CRXI ); 		// Waits for receive complete
I2CST_bit.I2CRXI=0; 		// Resets the I2C receive complete
					// interrupt flag

*data = I2CBUF; 			// Writes the data to the pointer
}
本站聲明: 本文章由作者或相關(guān)機構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點,本站亦不保證或承諾內(nèi)容真實性等。需要轉(zhuǎn)載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請及時聯(lián)系本站刪除。
換一批
延伸閱讀

2022 年 6 月 30 日,中國—— 依托在串行EEPROM技術(shù)領(lǐng)域的積累和沉淀,意法半導(dǎo)體率先業(yè)界推出了串行頁EEPROM (Serial Page EEPROM)。這款全新類別的EEPROM 是一種SPI串行接口...

關(guān)鍵字: 意法半導(dǎo)體 EEPROM 非易失性存儲器

包含中國在內(nèi),共計全球20個國家及地區(qū)可于線上收看 上海2022年6月21日 /美通社/ -- 萬代南夢宮娛樂股份有限公司(總公司:東京都港區(qū),社長:宮河恭夫)宣布將于2022年7月9日(周六)、7月10日(周日)兩日...

關(guān)鍵字: TE CST LM AI

(全球TMT2022年6月14日訊)6月14日-7月12日,2022年中國國際半導(dǎo)體技術(shù)大會(CSTIC2022)將以云分享的方式在線上舉辦。本屆會議將有九場專題討論會,超400場專業(yè)演講,4周網(wǎng)絡(luò)會議延續(xù)與講師的問答...

關(guān)鍵字: 半導(dǎo)體技術(shù) 安集科技 TI CST

單片機的存儲器可分為程序存儲器(ROM)和數(shù)據(jù)存儲器(RAM)。

關(guān)鍵字: EEPROM 記憶設(shè)備

▼點擊下方名片,關(guān)注公眾號▼存儲器分為兩大類:RAM和ROM。RAM就不講了,主要討論ROM。ROM最初不能編程,出廠什么內(nèi)容就永遠什么內(nèi)容,不靈活。后來出現(xiàn)了PROM,可以自己寫入一次,要是寫錯了,只能換一片,自認倒霉...

關(guān)鍵字: EEPROM Flash

摘要:英飛凌公司推出的TLE4997是一款全新的可編程線性霍爾傳感器。該傳感器經(jīng)過專門設(shè)計,可滿足需要精確角度和位置檢測的汽車級產(chǎn)品的苛刻要求。文中簡要介紹了該傳感器的主要特性,然后論述了其編程方法,最后給出了該傳感器編...

關(guān)鍵字: TLE4997 霍爾傳感器 Modbus EEPROM 微控制器

單片機在掉電時,電壓低過一定的值。執(zhí)行程序代碼出錯或是程序指針跑飛。剛好執(zhí)行EEPORM 寫入操作,才會出現(xiàn)所說的EEPROM 數(shù)據(jù)丟失!就算是外置EEPROM 在低于正常工作電壓,進行寫入操作,也會出現(xiàn)這種情況!

關(guān)鍵字: EEPROM 數(shù)據(jù)丟失

存儲器分為兩大類: ram 和 rom ,r am就不講了,主要討論rom。

關(guān)鍵字: 存儲器 EEPROM Flash

EEPROM的全稱是“電可擦除可編程只讀存儲器”,即Electrically Erasable Programmable Read-Only Memory。是相對于紫外擦除的ROM來講的。但是今天已經(jīng)存在多種EEPROM...

關(guān)鍵字: EEPROM Flash 存儲器

今天給小伙伴們整理了USB接口的類型,帶圖片說明,好辨識!

關(guān)鍵字: USB EEPROM

單片機

21600 篇文章

關(guān)注

發(fā)布文章

編輯精選

技術(shù)子站

關(guān)閉