周公的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协议,我怎么看怎么少唉,请大家来看看   此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。