打印
[技术问答]

24C02使用的疑问,关于读数据时显示最后一次写的值

[复制链接]
1062|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
niuyaliang|  楼主 | 2014-5-5 14:45 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
用的是新塘自带的库函数
Write_24LC64(0x00000000,'a');
        Temp = Read_24LC64(0x00000000);
        printf("%c\n",Temp);
       
        Write_24LC64(0x00000001,'b');
        Temp1 = Read_24LC64(0x00000001);
        printf("%c\n",Temp1);
这样读完输出的是a,b
Write_24LC64(0x00000000,'a');        
        Write_24LC64(0x00000001,'b');
       
        Temp = Read_24LC64(0x00000000);
        printf("%c\n",Temp);
        Temp1 = Read_24LC64(0x00000001);
        printf("%c\n",Temp1);
这样输出的是b,b
现在的问题是,连续读的时候,只显示最近一次写入的数据。。。不知道哪里出问题了
沙发
niuyaliang|  楼主 | 2014-5-5 15:32 | 只看该作者
从调试结果看,读到的是当前地址的数据,而不是写入地址的数据,读函数如下
uint8_t Read_24LC64(uint32_t address)
{
        uint8_t TEMP;
  //Open I2C1 and set clock = 50Kbps
        SystemCoreClock = DrvSYS_GetHCLKFreq();
        DrvI2C_Open(I2C_PORT1, 50000);
        //send i2c start
    DrvI2C_Ctrl(I2C_PORT1, 1, 0, 1, 0);                 //set start
        while (I2C1->I2CON.SI == 0);                                //poll si flag
         
           //send writer command
        I2C1->I2CDAT = 0XA0;
    DrvI2C_Ctrl(I2C_PORT1, 0, 0, 1, 0);           //clr si
    while( I2C1->I2CON.SI == 0 );                           //poll si flag
       
        //send address high
    I2C1->I2CDAT = (address>>8)&0XFF;       
        DrvI2C_Ctrl(I2C_PORT1, 0, 0, 1, 1);    //clr si and set ack
        while( I2C1->I2CON.SI == 0 );                           //poll si flag
   
        //send address low
        I2C1->I2CDAT = address&0XFF;       
        DrvI2C_Ctrl(I2C_PORT1, 0, 0, 1, 0);    //clr si        and set ack
        while( I2C1->I2CON.SI == 0 );                           //poll si flag
       
        //send start flag
        DrvI2C_Ctrl(I2C_PORT1, 1, 0, 1, 0);    //clr si and send start       
        while( I2C1->I2CON.SI == 0 );                           //poll si flag
       
        //send read command
        I2C1->I2CDAT = 0XA1;
        DrvI2C_Ctrl(I2C_PORT1, 0, 0, 1, 1);    //clr si
    while( I2C1->I2CON.SI == 0 );                           //poll si flag

        //resive data
        I2C1->I2CDAT = 0XFF;
        DrvI2C_Ctrl(I2C_PORT1, 0, 0, 1, 0);    //clr si       
        while( I2C1->I2CON.SI == 0 );                           //poll si flag
        TEMP= I2C1->I2CDAT;
        //send i2c stop
        DrvI2C_Ctrl(I2C_PORT1, 0, 1, 1, 0);    //clr si and set stop
        while( I2C1->I2CON.STO);
        DrvI2C_Close(I2C_PORT1);

        return TEMP;
}

使用特权

评论回复
板凳
zxf0168| | 2014-5-12 23:31 | 只看该作者
读到的是地址,而不是地址的数据

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

212

主题

2427

帖子

7

粉丝