I am using MPU6500 accelerometer in I2C mode. Datasheet explains the reading sequence on page 33.

It may seem easy for someone who is an expert but it is my first time using the I2C interfaced device. I have written a function but It doesn't read register values like WHO_AM_I etc.

    uint8_t Accelerometer_Read(uint8_t reg)
{

HAL_I2C_Master_Transmit(accelerometerhandle, 0x68|0x00, &reg, 1, 100);


• Use HAL_I2C_Mem_Read() instead. That will perform the correct sequence of Start-devAddr-regAddr-reStart-readData-Stop all for you. – brhans Aug 21 '20 at 14:39
• The alternative would b to use interrupts. Start with a HAL_I2C_Master_Seq_Transmit_IT(), then in the TxCplt callback do a HAL_I2C_Master_Seq_Receive_IT(). – brhans Aug 21 '20 at 14:44