cancel
Showing results for 
Search instead for 
Did you mean: 

Hello ST, i have an issue on I2C Bus. I want to communicate with an external device LTC3350.

MOtto.1
Associate II

I just like to read some internal register of this device after startup and also while application is running. But i2c allways retuns that it is busy and does not start any clocking observed via oscilloscope. Shows me all the time that it is busy register SR2 -> 2.

How can i reset this i2c module so that this register get reseted. The SR2 register is only readable due to it is an hardware register.I tryed to free clock it via SCL pins but did not not work it out either.

I use an stm32f105 and api commands like HAL_I2C_Mem_Read(...). Can you give me a help on that issue.

Thanks & Greetings

6 REPLIES 6

Do you have external pull-ups?

The I2C on the F1 has some initialization order issues, can be problematic if SCL is sensed low, as I recall.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
MOtto.1
Associate II

Yes i have external resistors on both 10K in value. I have seen some online descriptions on this topic on is using __HAL_RCC_I2C1_FORCE_RESET() ???

> does not start any clocking observed via oscilloscope

So, is SCL low or high?

You may also want to bit-bang the communication first.

JW

MOtto.1
Associate II

There are both high. I tried bit-bang but did not work for me. i clocked SCL low high several times.

But i recently tried to force reset and release rest and then init again and it seems to work now and i got my values as expected. I checked also online and one is mentioning that changing  to order  __HAL_RCC_I2C1_CLK_ENABLE(); before HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); inside hardware initialisation does it. Your opinion on that?

I don't use the 'F1 and I don't use Cube/HAL, but on 'F4 (which has similar I2C module than the 'F1) I do use a reset (in RCC, but I2C_CR1.SWRST should do the same job) before starting to configure the I2C module.

JW

MOtto.1
Associate II

This also worked for me. Can you confirm?

I will try yours now.

void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c)

{

 GPIO_InitTypeDef GPIO_InitStruct = {0};

 if(hi2c->Instance==I2C1)

 {

 /* USER CODE BEGIN I2C1_MspInit 0 */

   __HAL_RCC_I2C1_CLK_ENABLE(); <--------------------- this line--------------------

 /* USER CODE END I2C1_MspInit 0 */

   __HAL_RCC_GPIOB_CLK_ENABLE();

   /**I2C1 GPIO Configuration   

   PB6    ------> I2C1_SCL

   PB7    ------> I2C1_SDA

   */

   GPIO_InitStruct.Pin = COP_I2C1_SCL_Pin|COP_I2C1_SDA_Pin;

   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 */

 /* USER CODE END I2C1_MspInit 1 */

 }

}