cancel
Showing results for 
Search instead for 
Did you mean: 

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

DImre.1
Associate III

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!

2 REPLIES 2
TDK
Guru

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.

If you feel a post has answered your question, please click "Accept as Solution".
DImre.1
Associate III

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!