Skip to main content
Explorer II
June 12, 2024
Solved

Reading I2c with sub-address

  • June 12, 2024
  • 1 reply
  • 1737 views

Hello All.

Reading a register value from an I2C device assumes:  Writing the device address-> Writing the register address without STOP-> Reading the value . I am trying to figure out if I can do it using only available HAL functions but I don't see how. Simple Write followed by Read includes STOP, which is not in full compliant with the rules. 

Yes, if needed, I can rewrite everything but maybe there is an option, which I don't notice?

I use STM32G0B0 with HAL libraries.

 

    This topic has been closed for replies.
    Best answer by baranovus

    Thanks! That is the solution.

    1 reply

    Graduate II
    June 12, 2024

    For EEPROM, IMU, etc this form tends to be workable

    HAL_StatusTypeDef status = HAL_I2C_Mem_Read(&I2CHandle, (0x42 << 1), 0xFF, 1, buffer, len, 300); // Read data block from register position 0xFF (8-bit)

    Supports 8 and 16-bit addressing within the Slave, and whatever length auto-increments

    baranovusAuthorAnswer
    Explorer II
    June 20, 2024

    Thanks! That is the solution.