初中生
最后登录1970-1-1
在线时间 小时
注册时间2020-11-17
|
用模拟i2c写eeprom-24c02,可以实现单个数读、写,读多个数,但不能实现写多个数,测试了如下三个程序,都只能写入单个数,不知问题出在哪里。
void eeprom_write_bytes(uint8_t *_pWriteBuf, uint8_t _usAddress, uint8_t _usSize)
{
while(_usSize--){ eeprom_write_one_byte(_usAddress,*_pWriteBuf);
_usAddress++;
_pWriteBuf++;}
}
void eeprom_write_bytes(uint8_t *_pWriteBuf, uint8_t _usAddress, uint8_t _usSize)
{
uint8_t i; for (i = 0; i < _usSize-1; i++){
eeprom_write_one_byte(_usAddress,_pWriteBuf[i]);
_usAddress++;}
}
void eeprom_write_bytes(uint8_t *_pWriteBuf, uint8_t _usAddress, uint8_t _usSize)
{
uint8_t i;
i2c_start(); #define EEPROM_DEV_ADDR 0xA0 /* 24xx02的设备地址 */ i2c_send_byte(EEPROM_DEV_ADDR | EEPROM_I2C_WR); #define EEPROM_I2C_WR 0 /* 写控制bit */
i2c_wait_ack();
i2c_send_byte(_usAddress);
i2c_wait_ack();
for (i = 0; i < _usSize-1; i++){
i2c_send_byte(_pWriteBuf[i]);
i2c_wait_ack();}
i2c_stop();
}
|
|