Skip to main content
Explorer
May 10, 2020
Question

Why are bit 16. and 17. checked in HAL for the 16bit I2C status registers?

  • May 10, 2020
  • 2 replies
  • 1434 views

I checked I2C interrupt flags, when I realized at new interrupt bit 16 is also checked for SR1, bit 17 is also checked for SR2 registers, despite they are 16-bit registers. Why?

See attached picture for details.

Thanks in advance!

    This topic has been closed for replies.

    2 replies

    Super User
    May 10, 2020

    It's a 32 bit register, just the upper 16 bits are reserved.

    The 16th bit is used by HAL to hold which status register the flag is in.

    #define __HAL_I2C_GET_FLAG(__HANDLE__, __FLAG__) ((((uint8_t)((__FLAG__) >> 16U)) == 0x01U) ? \
     (((((__HANDLE__)->Instance->SR1) & ((__FLAG__) & I2C_FLAG_MASK)) == ((__FLAG__) & I2C_FLAG_MASK)) ? SET : RESET) : \
     (((((__HANDLE__)->Instance->SR2) & ((__FLAG__) & I2C_FLAG_MASK)) == ((__FLAG__) & I2C_FLAG_MASK)) ? SET : RESET))

    Maybe you're wanting to use I2C_SR1_SB, which is the register level definition.

    DImre.1Author
    Explorer
    May 10, 2020

    Thank you for the clarification! :)

    I did not plan to use SB, I just wanted to know if I need to check 16th bit when I use my own raw code instead of HAL. :) It is working only checking the actual bit to the corresponding flag, as you wrote the 16th bit is only for HAL. Thank you!