Wrong pinout configuration with LL_GPIO_Init()
GPIO_InitStruct.Pin = I2C1_SCL_Pin|I2C1_SDA_Pin;
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN;
LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
Code above makes pins I2C1_SCL_Pin and I2C1_SDA_Pin configured as Output Push-pull.
(can be observed in SFRs window, when debugging)
This causes wrong I2C behavior, when receiving ADDR ACK
conditions:
STM32CubeIDE Version: 1.4.2
chip: stm32f103CB
I2C configuration, including GPIO setting, generated by device configuration tool.
SDA is on PB7
SCL is on PB6
Fix (workaround): Configure pins using registers. Adding following code makes GPIO configuration correct and I2C function properly:
GPIOB->CRL |= (GPIO_CRL_CNF6_0|GPIO_CRL_CNF6_1);
GPIOB->CRL |= (GPIO_CRL_CNF7_0|GPIO_CRL_CNF7_1);
