cancel
Showing results for 
Search instead for 
Did you mean: 

I2C code on STM32Cube_FW_L0_V1.10.0

Fabian Inostroza
Associate
Posted on July 05, 2018 at 07:45

Hi,

Today I upgraded the firmware packages in STM32CubeMX and was looking at the differences with the version I had previously installed (v1.8.1 in the source files) and noticed the following definitions in stm32l0xx_hal_i2c.h:

#define  I2C_NO_STARTSTOP               (0x00000000U)

#define  I2C_GENERATE_STOP              (uint32_t)(0x80000000U | I2C_CR2_STOP)

#define  I2C_GENERATE_START_READ        (uint32_t)(0x80000000U | I2C_CR2_START | I2C_CR2_RD_WRN)

#define  I2C_GENERATE_START_WRITE       (uint32_t)(0x80000000U | I2C_CR2_START)

and the following code on stm32l0xx_hal_i2c.c, function I2C_TransferConfig:

  MODIFY_REG(hi2c->Instance->CR2, ((I2C_CR2_SADD | I2C_CR2_NBYTES | I2C_CR2_RELOAD | I2C_CR2_AUTOEND | (I2C_CR2_RD_WRN & (uint32_t)(Request >> (31U - I2C_CR2_RD_WRN_Pos))) | I2C_CR2_START | I2C_CR2_STOP)), \

             (uint32_t)(((uint32_t)DevAddress & I2C_CR2_SADD) | (((uint32_t)Size << I2C_CR2_NBYTES_Pos) & I2C_CR2_NBYTES) | (uint32_t)Mode | (uint32_t)Request));

I would like to know why the I2C_GENERATE_* definitions are ORed with 0x80000000?, in the datasheet I'm looking (stm32l051) the msb is defined as reserved, also, the second argument in the macro MODIFY_REG includes this:

(I2C_CR2_RD_WRN & (uint32_t)(Request >> (31U - I2C_CR2_RD_WRN_Pos)))

and it doesn't make much sense, is there something I am missing?
0 REPLIES 0