Skip to main content
Visitor II
July 13, 2023
Question

HAL_SMBUS_xxx wrong documentation suggests shifiting DevAddress

  • July 13, 2023
  • 3 replies
  • 1308 views

In the comment to the functions it says (stm32f4xx_hal_smbus.c)

 

* @PAram DevAddress Target device address The device 7 bits address value
 * in datasheet must be shifted to the left before calling the interface

 

I suspect this was copy & pasted from the I2C driver. When not shifting the address the driver works.

    This topic has been closed for replies.

    3 replies

    Super User
    July 13, 2023

    For the ST HAL I2C drivers, the address should not be shifted. The R/W flag in LSB is OR'ed.

    Maybe this comment relates to device data sheets that follow the Linux i2c convention.

    Graduate II
    August 7, 2023

    For the ST HAL I2C drivers, the address should not be shifted. The R/W flag in LSB is OR'ed.


    Which means exactly the opposite - the address should be shifted left by 1 bit. I2C addresses are 7-bit, not 8-bit in size. ;)

    siquusAuthor
    Visitor II
    July 13, 2023

    Hi,

    Thanks! Then it would be nice to elaborate in that comment please. It took me quite some time until I by accident forgot to shift the address (as supplied in Texas Instruments Datasheet) and suddenly it worked :)

    ST Employee
    August 1, 2023

    Dear,

    This message is correct in the driver. No issue copy/paste.

    In fact this message have been added as some "old" I2C slave document shared the address of their device in real 7bits definition. So it will be necessary to shift it to the left to put it in 8bits word.

    Now, if your device already declare the address in 8bits in its appropriate datasheet, no need to shift it. Our recommendation is only for datasheet which share the device address in real 7bits.

    HAL driver not support the internal shifting, to prevent the disparity of the datasheet owner definition of the I2C address.

    Hope that clear now

    Regards