Skip to main content
BCogh.2
Associate II
November 1, 2021
Solved

Does STM32CubeMX/HAL have the ability to configure the I2C_CR1's ACK bit on the STM32L151xx?

  • November 1, 2021
  • 2 replies
  • 962 views

I am currently attempting to port a product's older firmware that used the Standard Peripheral Driver libraries over to using the HAL libraries for greater portability between different MCUs. I a currently using the STM32L151QEHx.

In the older firmware the I2C is initialized using the following initialization structure:

 /* Configure I2C settings within custom init function */
I2cConfig.I2C_ClockSpeed = I2cClockSpeed; //passed into init function
I2cConfig.I2C_Mode = I2C_Mode_I2C;
I2cConfig.I2C_DutyCycle = I2C_DutyCycle_2;
I2cConfig.I2C_OwnAddress1 = 0;
I2cConfig.I2C_Ack = I2C_Ack_Enable;
I2cConfig.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;

Of interest is the code on line 6 where the I2C_Ack value is set. The ability to set this option does not appear to be available in STM32CubeMX or in the HAL libraries, but something similar does appear in the LL drivers included with the HAL libraries.

Am I missing a HAL defined way to set the I2C_CR1 ACK bit, or is this simply not available via HAL APIs?

Thank you for your time,

Brian C.

This topic has been closed for replies.
Best answer by TDK

It is set within HAL appropriately based on how many bytes you're sending and where you are in the transaction. See:

https://github.com/STMicroelectronics/STM32CubeL1/blob/dd75b08e4ed505fabe7b6b61120b18094e768973/Drivers/STM32L1xx_HAL_Driver/Src/stm32l1xx_hal_i2c.c#L1206

https://github.com/STMicroelectronics/STM32CubeL1/blob/dd75b08e4ed505fabe7b6b61120b18094e768973/Drivers/STM32L1xx_HAL_Driver/Src/stm32l1xx_hal_i2c.c#L1299

It's not something that should be set during initialization of the peripheral, but rather at the start and during a transaction.

2 replies

TDK
TDKBest answer
November 1, 2021

It is set within HAL appropriately based on how many bytes you're sending and where you are in the transaction. See:

https://github.com/STMicroelectronics/STM32CubeL1/blob/dd75b08e4ed505fabe7b6b61120b18094e768973/Drivers/STM32L1xx_HAL_Driver/Src/stm32l1xx_hal_i2c.c#L1206

https://github.com/STMicroelectronics/STM32CubeL1/blob/dd75b08e4ed505fabe7b6b61120b18094e768973/Drivers/STM32L1xx_HAL_Driver/Src/stm32l1xx_hal_i2c.c#L1299

It's not something that should be set during initialization of the peripheral, but rather at the start and during a transaction.

"If you feel a post has answered your question, please click ""Accept as Solution""."
BCogh.2
BCogh.2Author
Associate II
November 1, 2021

Thank you very much, this answers it. I assumed there was a very good reason it was no longer included as a parameter to initialize, I just couldn't find out why.