在线时间21 小时
UID3317185
注册时间2018-6-18
NXP金币0
TA的每日心情 | 擦汗 2019-2-26 17:09 |
---|
签到天数: 6 天 连续签到: 1 天 [LV.2]偶尔看看I
注册会员

- 积分
- 196
- 最后登录
- 2019-4-11
|

楼主 |
发表于 2019-2-25 10:29:38
|
显示全部楼层
写数据没什么问题,读数据不正常。以下是我自己根据时序写的读函数。
- uint8_t I2C_MMA8451_Read(I2C_Type *pI2Cx,uint16_t u16SlaveAddress,uint8 RegAddress,uint8_t *pRdBuff,uint16_t u32Length)
- {
- uint8_t i,u8ErrorStatus;
- I2C_Start(pI2Cx);
- I2C_WriteOneByte(pI2Cx,((uint8_t)u16SlaveAddress));
- I2C_WriteOneByte(pI2Cx,((uint8_t)RegAddress));
- // I2C_Stop(pI2Cx);
- I2C_RepeatStart(pI2Cx);
- u8ErrorStatus = I2C_WriteOneByte(pI2Cx,((uint8_t)u16SlaveAddress)|0x01);
- if( u8ErrorStatus == I2C_ERROR_NULL )
- {
- for(i=0;i<u32Length-1;i++)
- {
- u8ErrorStatus = I2C_ReadOneByte(pI2Cx,&pRdBuff[i],I2C_SEND_ACK);
- if( u8ErrorStatus != I2C_ERROR_NULL )
- {
- return u8ErrorStatus;
- }
- }
- u8ErrorStatus = I2C_ReadOneByte(pI2Cx,&pRdBuff[i],I2C_SEND_NACK);
- }
- u8ErrorStatus = I2C_Stop(pI2Cx);
-
- return u8ErrorStatus;
- }
复制代码 |
|