周公的LPC1114开发板IIC程序是不是有点毛病大家看看

2019-03-25 20:42发布

/*********************************************************************************************************
** Function name:       I2C_ReadNByte
** Descriptions:        从有子地址器件任意地址开始读取N字节数据
** input parameters:    sla         器件地址
**                      suba_type   子地址结构    1-单字节地址    2-8+X结构    2-双字节地址
**                      suba        器件子地址
**                      s           数据接收缓冲区指针
**                      num         读取的个数
** Output parameters:   返回值为0时表示出错,为1时表示操作正确。
** Returned value:      NONE
*********************************************************************************************************/
INT8U I2C_ReadNByte (INT8U sla, INT32U suba_type, INT32U suba, INT8U *s, INT32U num)
{
    if (num > 0) {                                                      /* 判断num个数的合法性          */
                                                                        /* 参数设置                     */
        if (suba_type == 1) {                                           /* 子地址为单字节               */
            I2C_sla         = sla+1;                    /* 读器件的从地址,R=1          */
            I2C_suba        = suba;                                     /* 器件子地址                   */
            I2C_suba_num    = 1;                                        /* 器件子地址为1字节            */
        }
        if (suba_type == 2) {                                           /* 子地址为2字节                */
            I2C_sla         = sla + 1;                                  /* 读器件的从地址,R=1          */
            I2C_suba        = suba;                                     /* 器件子地址                   */
            I2C_suba_num    = 2;                                        /* 器件子地址为2字节            */
        }
        if (suba_type == 3) {                                           /* 子地址结构为8+X              */
            I2C_sla         = sla + ((suba >> 7 )& 0x0e) + 1;           /* 读器件的从地址,R=1          */
            I2C_suba        = suba & 0x0ff;                             /* 器件子地址                   */
            I2C_suba_num    = 1;                                        /* 器件子地址为8+x              */
        }
        I2C_buf     = s;                                                /* 数据接收缓冲区指针           */
        I2C_num     = num;                                              /* 要读取的个数                 */
        I2C_suba_en = 1;                                                /* 有子地址读                   */
        I2C_end     = 0;
                                                                        /* 清除STA,SI,AA标志位          */
        I2CCONCLR = (1 << 2) |                                          /* AA                           */
        (1 << 3) |                                                      /* SI                           */
        (1 << 5);                                                       /* STA                          */                                                                         /* 置位STA,启动I2C总线          */
        I2CCONSET = (1 << 5) |                                          /* STA                          */
        (1 << 6);                                                       /* I2CEN                        */         return( Wait_I2c_End(20);                                                                /* 等待I2C操作完成              */
               
    }
    return (FALSE);
}   这个是例程上的读函数,我看有点毛病,读时序为什么地址先加一,好象少了一步唉   IIC.JPG       大家看下现在读不出来,我觉得有病,在周公论谈问,让我看IIC协议,我怎么看怎么少唉,请大家来看看   此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
4条回答
elulis
1楼-- · 2019-03-25 22:46
 精彩回答 2  元偷偷看……
elulis
2楼-- · 2019-03-26 02:14
24C02_04_08_16_32_64中文_v10.pdf (1.36 MB, 下载次数: 90) 2010-11-22 01:14 上传 点击文件名下载附件
ddllxxrr
3楼-- · 2019-03-26 03:04
我那个图的第一个<signle byte read>第一个是写地址,就是LSB是0然后再读从地址LSB为1,可是例子只体现了读,前面那个写呢???
elulis
4楼-- · 2019-03-26 04:06
写的话LSB肯定是0的,应该也有个写的函数吧。我没有周公的板子和程序,楼主自己找找

一周热门 更多>