cancel
Showing results for 
Search instead for 
Did you mean: 

Why “HAL_I2C_Master_Transmit�? writes 2 bytes of data in each loop?

SGolm
Associate

I'm using HAL library for stm32f4 (V1.7.1) and trying to understand how HAL_I2C_Master_Transmit works. This function transmits a master to slave packet on SDA line.

In the stm32f4xx_hal_i2c.c code after sending slave address there is a loop (while(hi2c->XferSize > 0U)) that sends bytes which we want to be transmitted to slave. This loop works until all bytes are transmitted.

But there is a question that "why the function wants to transmit TWO bytes in each loop?" There is an IF in loop (if((__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BTF) == SET) && (hi2c->XferSize != 0U))) that checks if the previous byte is currently transferred then send the the next byte! I don't know what is the reason of existing this IF when in the next loop other bytes can be transmitted?!

0 REPLIES 0