arm的i2c接口读,需要连读2次才可以吗?
int i2c_read(int reg_offset){
int data;
int activity;
// reg_offset = reg_offset | 0x100 ;
// mem_wr_i2c(0x10, reg_offset); // IC_DATA_CMD: set register address
*(volatile UINT32 *)0x18500010 = reg_offset;
// mem_wr_i2c(0x10, 0x100); // IC_DATA_CMD: set read bit
*(volatile UINT32 *)0x18500010 = 0x100;
ic_status = mem_rd_i2c(0x70); // IC STATUS register. LSB is the common activity bit
activity = ic_status & 0x1;
while (activity == 0)
{
ic_status = mem_rd_i2c(0x70); // IC STATUS register. LSB is the common activity bit
activity = ic_status & 0x1;
}
data = mem_rd_i2c(0x10); // IC_DATA_CMD: read returned register value
//printf("1:%d\n",data);
ic_status = mem_rd_i2c(0x70); // IC STATUS register. LSB is the common activity bit
activity = ic_status & 0x1;
while (activity == 1)
{
readCounter++;
ic_status = mem_rd_i2c(0x70); // IC STATUS register. LSB is the common activity bit
activity = ic_status & 0x1;
}
data = mem_rd_i2c(0x10); // IC_DATA_CMD: read returned register value
printf("2:%d\n",data);
return (data);
}
这段代码,就是i2c状态关闭的时候,从data线读一次:
data = mem_rd_i2c(0x10);
然后i2c从激活状态到未激活状态在读一次,这次的值才真正的返回,这段代码如果把第一处代码注释,
data = mem_rd_i2c(0x10);
程序i2c通讯不正确了。。。
也就是必须读2次,问题是,为什么??
核心是arm内核 自己顶。。。。。。。。 什么ARM,ARM9?信息他少,无解! 回复【2楼】changhui0222
什么arm,arm9?信息他少,无解!
-----------------------------------------------------------------------
ARM 926,然后答应出来的值是这样的:
1:3
2:86
1:86
2:23
也就是先读的那一次,是之前的那个值,我不知道为什么这么做。。。感觉好像读一次才能写入新值。。但是么听说这么荒唐的事。。 ARM 926
页:
[1]