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

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

 引言

  本文介紹了如何通過MAX2990電力線通信調(diào)制解調(diào)器的I2C接口與外部EEPROM 24C04連接,并給出了相應的固件例程。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留出足夠的寫時間非常關鍵。通常在“停止條件”后留出幾個毫秒的時間,請參考數(shù)據(jù)資料,確認您的時間設置符合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[!--empirenews.page--]

現(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
}
本站聲明: 本文章由作者或相關機構授權發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點,本站亦不保證或承諾內(nèi)容真實性等。需要轉(zhuǎn)載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權益,請及時聯(lián)系本站刪除。
換一批
延伸閱讀

在現(xiàn)代電子設備中,電可擦可編程只讀存儲器(EEPROM)憑借其獨特的存儲特性,被廣泛應用于各類需要非易失性數(shù)據(jù)存儲的場景。從智能電表、工業(yè)控制系統(tǒng)到消費電子產(chǎn)品,EEPROM 承擔著存儲關鍵配置信息、校準數(shù)據(jù)以及用戶個性...

關鍵字: 只讀存儲器 數(shù)據(jù)存儲 EEPROM

在嵌入式系統(tǒng)和存儲設備領域,F(xiàn)lash和EEPROM(電可擦可編程只讀存儲器)因其非易失性存儲特性而被廣泛應用。這些存儲設備能夠在斷電后保持數(shù)據(jù),對于需要長期保存配置參數(shù)、程序代碼或用戶數(shù)據(jù)的應用來說至關重要。然而,關于...

關鍵字: Flash EEPROM

沙特阿拉伯利雅得2024年12月13日 /美通社/ -- 第19屆聯(lián)合國互聯(lián)網(wǎng)治理論壇(IGF)即將于2024年12月15日至19日在位于利雅得的阿卜杜勒?阿齊茲國王國際會議中心舉行。全球行業(yè)領袖將齊聚一堂,共同討論包括...

關鍵字: 互聯(lián)網(wǎng) BSP 通信 CST

在嵌入式系統(tǒng)中,諸如變頻器和伺服驅(qū)動器等工業(yè)應用,乃至CD播放器等眾多消費電子產(chǎn)品,都需要保存最近的用戶設置,在下次上電后加載使用。如果使用MCU內(nèi)置Flash,一般擦寫次數(shù)限制在10k次,無法滿足壽命和耐久性要求,所以...

關鍵字: MSP EEPROM

在嵌入式系統(tǒng)開發(fā)中,EEPROM(電可擦可編程只讀存儲器)常用于存儲需要持久保存的數(shù)據(jù)。然而,當在S32DS(一款常用于嵌入式系統(tǒng)開發(fā)的集成開發(fā)環(huán)境)上結合FreeRTOS(一個實時操作系統(tǒng))進行開發(fā)時,可能會遇到仿真E...

關鍵字: 嵌入式 S32DS EEPROM

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

關鍵字: 意法半導體 EEPROM 非易失性存儲器

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

關鍵字: TE CST LM AI
關閉