共2条
1/1 1 跳转至页
,I2C,DelayNS,10 为什么I2C写操作之后,必须要DelayNS(10); 才能进行读操作?

问
int main (void)
{
uint8 i;
uint8 data_buf[32];
PINSEL0 = 0x00000000;
PINSEL1 = 0x00000000;
IO0DIR = BEEP;
IO0SET = BEEP;
IRQEnable();
I2cInit(400000);
for (i=0; i<10; i++)
data_buf[i] = i + '0';
I2C_WriteNByte(CAT24C16, X_ADD_8_SUBA, 0x00, data_buf, 10);
DelayNS(10); //在I2C写操作之后,
//为什么必须要延时,才能进行读操作?
for (i=0; i<10; i++)
data_buf[i] = 0;
I2C_ReadNByte(CAT24C16, X_ADD_8_SUBA, 0x00, data_buf, 10);
for (i=0; i<10; i++)
{
if (data_buf[i] != (i + '0'))
{
while (1)
{
IO0SET = BEEP;
DelayNS(20);
IO0CLR = BEEP;
DelayNS(20);
}
}
}
IO0CLR = BEEP;
DelayNS(50);
IO0SET = BEEP;
while (1);
return 0;
} 答 1: 我吃饱了,一般先睡一会在上班 答 2: 要吗?不要! 我网站有IIC读写EEPROM的程序,可以从任意地址、任意长度读写 答 3: 为什么要延迟了?数据手册里写得比较清楚.
一般的EEPROM,每发送完写指令和写数据时,
必须要有一个5-10ms的延迟.
否则数据写不进,
不信你可以试一下. 答 4: 谢谢哦! 答 5: 对于串行EEPROM的写操作,建议采用ACKNOWLEDGE POLLING代替延时ACKNOWLEDGE POLLING: Once the internally-timed write cycle has started and the EEPROM inputs are disabled, acknowledge polling CAN be initiated. This involves sending a start condition followed by the device address word. The Read/Write bit is representative of the operation desired. Only if the internal write cycle has completed will the EEPROM respond with a “0”, allowing the read or write sequence to continue. 答 6: 简单地说就是在串行EEPROM开始内部写操作过程到完成这段时间,不管你试图进行读或者写操作,芯片都不会响应。
这样一来你就可以不断地尝试向该器件发出start condition,当它以“0”来应答时,则表明它的上一个写过程已经完成,你可以接着进行下一步的操作了。
延时是一种相对简单的方法,个人认为ACKNOWLEDGE POLLING更省时,适应性更强。 答 7: john_light说得很正确.
{
uint8 i;
uint8 data_buf[32];
PINSEL0 = 0x00000000;
PINSEL1 = 0x00000000;
IO0DIR = BEEP;
IO0SET = BEEP;
IRQEnable();
I2cInit(400000);
for (i=0; i<10; i++)
data_buf[i] = i + '0';
I2C_WriteNByte(CAT24C16, X_ADD_8_SUBA, 0x00, data_buf, 10);
DelayNS(10); //在I2C写操作之后,
//为什么必须要延时,才能进行读操作?
for (i=0; i<10; i++)
data_buf[i] = 0;
I2C_ReadNByte(CAT24C16, X_ADD_8_SUBA, 0x00, data_buf, 10);
for (i=0; i<10; i++)
{
if (data_buf[i] != (i + '0'))
{
while (1)
{
IO0SET = BEEP;
DelayNS(20);
IO0CLR = BEEP;
DelayNS(20);
}
}
}
IO0CLR = BEEP;
DelayNS(50);
IO0SET = BEEP;
while (1);
return 0;
} 答 1: 我吃饱了,一般先睡一会在上班 答 2: 要吗?不要! 我网站有IIC读写EEPROM的程序,可以从任意地址、任意长度读写 答 3: 为什么要延迟了?数据手册里写得比较清楚.
一般的EEPROM,每发送完写指令和写数据时,
必须要有一个5-10ms的延迟.
否则数据写不进,
不信你可以试一下. 答 4: 谢谢哦! 答 5: 对于串行EEPROM的写操作,建议采用ACKNOWLEDGE POLLING代替延时ACKNOWLEDGE POLLING: Once the internally-timed write cycle has started and the EEPROM inputs are disabled, acknowledge polling CAN be initiated. This involves sending a start condition followed by the device address word. The Read/Write bit is representative of the operation desired. Only if the internal write cycle has completed will the EEPROM respond with a “0”, allowing the read or write sequence to continue. 答 6: 简单地说就是在串行EEPROM开始内部写操作过程到完成这段时间,不管你试图进行读或者写操作,芯片都不会响应。
这样一来你就可以不断地尝试向该器件发出start condition,当它以“0”来应答时,则表明它的上一个写过程已经完成,你可以接着进行下一步的操作了。
延时是一种相对简单的方法,个人认为ACKNOWLEDGE POLLING更省时,适应性更强。 答 7: john_light说得很正确.
共2条
1/1 1 跳转至页
回复
打赏帖 | |
---|---|
嵌入式LinuxC语言程序调试和宏使用技巧被打赏50分 | |
让代码中包含最新的编译时间信息被打赏50分 | |
rtthread硬件加密--2crc加密分析被打赏10分 | |
【分享开发笔记,赚取电动螺丝刀】mcxa156使用低功耗定时器适配硬件RTC框架被打赏26分 | |
【STM32F769】AI之与本地deepseek对接被打赏50分 | |
Buck电路工作在CCM模式下电感电流的计算公式是什么?被打赏5分 | |
buck电路工作原理被打赏5分 | |
基于MSPM0L1306的MODBUS-RTU协议通讯实验被打赏100分 | |
我想要一部加热台+多合一调试工具被打赏18分 | |
每周了解几个硬件知识+485硬件知识分享被打赏10分 |