Hi i forgot to add the dummy read thats why it was giving random values if we read from the bus now i have changed my code in order to make dummy read and then read now it works fine.... This above code is not from iic driver file. I have written this register read functionality in order to read from register....
uint8_t I2C_MasterRegisterReadWait(I2C_Type *pI2Cx,uint8_t u8SlaveAddress, uint8_t u8RegisterAddress,uint8_t *pRdBuff)
{
uint8_t u8ErrorStatus=0;
/* send start signals to bus */
u8ErrorStatus = I2C_Start(pI2Cx);
/* send device address to slave */
u8ErrorStatus = I2C_WriteOneByte(pI2Cx,((uint8_t)u8SlaveAddress<<1) | I2C_WRITE);
if( u8ErrorStatus != I2C_ERROR_NULL )
{
return u8ErrorStatus;
}
u8ErrorStatus = I2C_WriteOneByte(pI2Cx,((uint8_t)u8RegisterAddress) );
if( u8ErrorStatus != I2C_ERROR_NULL )
{
return u8ErrorStatus;
}
u8ErrorStatus = I2C_RepeatStart(pI2Cx);
if( u8ErrorStatus != I2C_ERROR_NULL )
{
return u8ErrorStatus;
}
u8ErrorStatus = I2C_WriteOneByte(pI2Cx,((uint8_t)u8SlaveAddress<<1) | I2C_READ);
if( u8ErrorStatus != I2C_ERROR_NULL )
{
return u8ErrorStatus;
}
/* 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 */
u8ErrorStatus = I2C_ReadOneByte(pI2Cx,&pRdBuff[0],I2C_SEND_NACK);
if( u8ErrorStatus != I2C_ERROR_NULL )
{
return u8ErrorStatus;
}
u8ErrorStatus = I2C_ReadOneByte(pI2Cx,&pRdBuff[0],I2C_SEND_NACK);
if( u8ErrorStatus != I2C_ERROR_NULL )
{
return u8ErrorStatus;
}
/* send stop signals to bus */
u8ErrorStatus = I2C_Stop(pI2Cx);
return u8ErrorStatus;
}