Skip to main content
Visitor II
March 10, 2020
Question

I2C HAL own address format?

  • March 10, 2020
  • 3 replies
  • 4244 views

I have been struggling to get a simple I2C communication link working so that I can talk to my battery charger device. It's device address is 0x68. I have tried shifting this one bit the the left, not shifting the address. Nether works. Can someone shed some light on this statement in the HAL UM1905 User Manual?

DevAddress: Target device address: The device 7 bits
address value in datasheet must be shift at right before call
interface

    This topic has been closed for replies.

    3 replies

    Super User
    March 10, 2020

    Cube/HAL is open source. You may be better off finding where is it stored to the actual register.

    JW

    Super User
    March 10, 2020

    > * @param DevAddress Target device address The device 7 bits address value

    > * in datasheet must be shifted to the left before calling the interface

    It expects the slave address to be in the upper 7 bits, so shift it one bit to the right when you call HAL_I2C_* functions.

    The HAL is documented pretty well without the source code. Perhaps look there first.

    Super User
    March 10, 2020

    For the ST I2C driver, I2C addresses are 7 bit, but shifted 1 bit left.

    Then you set bit 0 to 1 for write and 0 for read,

    In your hardware documentation, the address may be specified as 7 bit without shift.

    This form is common in Linux, for example.

    So 0x68 may mean either 0x68/0x69, or 0xD0/0xD1. Try both variants.

    ST library has a convenient function HAL_I2C_IsDeviceReady , it can be used to probe the addresses. Most decent devices should reply.

    -- pa