首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 嵌入开发 > 驱动开发 >

arm的i2c接口读,需要连读2次才可以吗?该怎么解决

2012-03-16 
arm的i2c接口读,需要连读2次才可以吗?C/C++ codequarticarm发表于 昨天 13:32 | 只看该作者 回复 引用 编

arm的i2c接口读,需要连读2次才可以吗?

C/C++ code
  quarticarm发表于 昨天 13:32 | 只看该作者 回复 引用 编辑 订阅 收藏 分享 评分打印楼主: arm的i2c接口读,需要连读2次才可以吗?接口, arm, activity, register, addressint 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次,问题是,为什么??
核心是arm926内核

[解决办法]
代码贴的太乱了,IIC怎么会读两次才能工作呢,哪颗CPU?

热点排行