新闻中心

EEPW首页>嵌入式系统>设计应用> 通过MAX2990 I2C接口向标准EEPROM (24C04)连接的方法

通过MAX2990 I2C接口向标准EEPROM (24C04)连接的方法

作者: 时间:2012-02-21 来源:网络 收藏

 引言

本文引用地址://m.amcfsurvey.com/article/172019.htm

  本文介绍了如何电力线通信调制解调器的与外部,并给出了相应的固件例程。I²C总线受控于(主机),为从机器件。以下框图给出了本文示例的硬件配置。

硬件配置 www.elecfans.com


  固件说明

  I²C初始化

  一旦使能I²C模块,SCL和SDA必须配置成漏极开路状态,以确保I²C总线通信正常。由于I²C是GPIO端口的一个替代功能,固件必须确保SCL和SDA输入在初始化期间禁止上拉(对端口控制器的输出位写零实现)。

示例中,时钟频率为250kHz。首先需要配置的I²C

PO1_bit.Bit2 = 0; // Disables the GPIO function of thePO1_bit.Bit3 = 0; //pinsCN_bit.I2CEN = 0; // Makes sure that I2C is disabled// to allow the changing of the I2C settingsI2CCN_bit.I2CMST = 1; // Sets the I2C engine to master modeI2CCN_bit.I2CEA = 0; // 7-bit address modeI2CCK_bit.I2CCKL = 0x40; // 2µs CLK-low, to define I2C frequencyI2CCK_bit.I2CCKH = 0x40; // 2µs CLK-high, to define I2C frequencyI2CTO = 200; // I2C_TIMEOUTI2CST = 0x400; // Resets I2C status registerI2CCN_bit.I2CEN = 1; // Enables the I2C engine

写模式

写入时,必须I²C接口写入以下字节:

  1. EEPROM的I²C总线地址(这里为0xA0)
  2. EEPROM存储器的地址
  3. 数据字节(地址将自动递增)

示例中试图写入以下字节,从0x00地址开始,向EEPROM写入:0x12、0x34、0x56、0x78和0x90。

i2c_init_write(); // Sets the MAX2990 I2C Engine into write modei2c_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// automaticallyi2c_write(0x00); // word address locationi2c_write(0x12); // data1i2c_write(0x34); // data2i2c_write(0x56); // data3i2c_write(0x78); // data4i2c_write(0x90); // data5I2C_STOP; // Sends I2C stop-condition


读模式

读取我们写入EEPROM的数据时,为24C04留出足够的写时间非常关键。通常在“停止条件”后留出几个毫秒的时间,请参考数据资料,确认您的时间设置符合IC的要求。

i2c_init_write(); // Sets the MAX2990 I2C engine into write modei2c_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// automaticallyi2c_write(0x00); // word address locationi2c_init_read(); // Sets the MAX2990 I2C engine into read modei2c_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// automaticallyunsigned char data[5]; // Array to store the received datai2c_read(data[0]); // Reads 1 byte from I2C and writes it to the arrayi2c_read(data[1]); // Reads 1 byte from I2C and writes it to the arrayi2c_read(data[2]); // Reads 1 byte from I2C and writes it to the arrayi2c_read(data[3]); // Reads 1 byte from I2C and writes it to the arrayi2c_read(data[4]); // Reads 1 byte from I2C and writes it to the arrayI2C_STOP; // Sends I2C stop-condition
        
        
        
上一页 1 2 下一页

评论


相关推荐

技术专区

关闭