cancel
Showing results for 
Search instead for 
Did you mean: 

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

BCogh.2
Associate II

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.

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

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".

View solution in original post

2 REPLIES 2
TDK
Guru

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
Associate II

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.