• 易迪拓培训,专注于微波、射频、天线设计工程师的培养
首页 > 无线通信 > 技术文章 > 如何通过MAX2990 I2C接口向标准EEPROM (24C04)连接

如何通过MAX2990 I2C接口向标准EEPROM (24C04)连接

录入:edatop.com     点击:

读模式

读取我们写入EEPROM的数据时,为24C04留出足够的写时间非常关键。通常在"停止条件"后留出几个毫秒的时间,请参考数据资料,确认您的时间设置符合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

现在,我们可以验证一下用于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
}

来源:电子发烧友

我推荐大家读

轻松参与

VS

表达立场

这是垃圾文章

上一篇:高速差分接口及共模滤波与保护的需求
下一篇:深入讲解路由器技术POS接入方式

手机天线设计培训教程详情>>

手机天线设计培训教程 国内最全面、系统、专业的手机天线设计培训课程,没有之一;是您学习手机天线设计的最佳选择...【More..

射频和天线工程师培训课程详情>>

  网站地图