I'm using the KEAZ128 and I just downloaded the quick start package which has a bunch of test drivers in it. I started using the polling i2c driver and noticed that its reading two bytes out of the i2c register called instead of one? Has anyone else encountered this problem with this code? Here is the read function from the file:
uint8_t I2C_MasterReadWait(I2C_Type *pI2Cx,uint16_t u16SlaveAddress,uint8_t *pRdBuff,uint32_t u32Length)
{
uint32_t i;
uint8_t u8ErrorStatus;
/* send start signals to bus */
u8ErrorStatus = I2C_Start(pI2Cx);
/* send device address to slave */
u8ErrorStatus = I2C_WriteOneByte(pI2Cx,u16SlaveAddress | I2C_READ);
/* if no error occur, received the correct ack from slave
continue to send data to slave
*/
/* dummy read one byte to switch to Rx mode */
I2C_ReadOneByte(pI2Cx,&pRdBuff[0],I2C_SEND_ACK);
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);
}
/* send stop signals to bus */
u8ErrorStatus = I2C_Stop(pI2Cx);
return u8ErrorStatus;
}
Hi
Please refer the "Figure 31-42. Typical I2C interrupt routine" in KEA128RM.
u8ErrorStatus = I2C_ReadOneByte(pI2Cx,&pRdBuff[i],I2C_SEND_NACK); is used to read one byte out of the i2c register.
Best Regards,
Robin
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
---------------------------------------------------------------------------------------------------------------------