Hello again,
Finally solved the issue...
Here's what needs to be added to code from CubeMx to make it work...
void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c)
{
GPIO_InitTypeDef GPIO_InitStruct;
if(hi2c->Instance==I2C1)
{
/* USER CODE BEGIN I2C1_MspInit 0 */
/* USER CODE END I2C1_MspInit 0 */
/**I2C1 GPIO Configuration
PB6 ------> I2C1_SCL
PB7 ------> I2C1_SDA
*/
GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/* Peripheral clock enable */
__HAL_RCC_I2C1_CLK_ENABLE();
/* USER CODE BEGIN I2C1_MspInit 1 */
__HAL_RCC_I2C1_FORCE_RESET(); // <---------------------------- Reset I2C module, before re-initializing
HAL_Delay( SYS_TICKS_1S/100 ); // <---------------------------- This delay required otherwise I2C module remains reset
__HAL_RCC_I2C1_RELEASE_RESET(); // <----------------------------
/* USER CODE END I2C1_MspInit 1 */
}
}
Also, if you are also using FSMC, make sure you disable FSMC clock before accessing I2C &/or vice versa...
// Disable I2C clock & Enable FSMC clock
__HAL_RCC_FSMC_CLK_ENABLE();
__HAL_RCC_I2C1_CLK_DISABLE();
// Can Use FSMC immediately
// Disable FSMC clock & enable I2C clock
__HAL_RCC_FSMC_CLK_DISABLE();
__HAL_RCC_I2C1_CLK_ENABLE();
// at least 10mS delay required before actually accessing I2C module, else again locked in infinite busy loop
Hope this helps others.
Thanks.
sam_des