AnsweredAssumed Answered

i2c bus reads 2 bytes instead of one?

Question asked by Alexandra Dickie on Dec 18, 2016
Latest reply on Dec 20, 2016 by Robin_Shen

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;
}

Outcomes