cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F205. I2C failed to start hi2c1, but hi2c2 is worked fine. Generated from CubeMX version 5.6.0

AKunc.1
Associate II

I use code generation tool STM32CubeMX in order to generate initiation function. However when I want to implement I2C1 I have a strange problem. STM32Cube generates all necessary initiation steps. In main function in while I try to check is someone on a line by function HAL_I2C_IsDeviceReady(&hi2c1, 0x90, 10, 100) and fuinc I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_SB, RESET, Timeout, tickstart) returned me HAL_ERROR. If i generate I2C2 and do the same I can see fine logic signals on SCL and SDA/

7 REPLIES 7
TDK
Guru

Is the I2C1 bus in use by something else? Is a misbehaving slave holding SCL low?

If you feel a post has answered your question, please click "Accept as Solution".
AKunc.1
Associate II

Bus is free without anyone. SCL and SDA are with pull up resistors 4.7k Ohm

AKunc.1
Associate II

The fact is that I checked this code and initialization on STM32F205VEt6 it does not work, but on STM32F205REt6 it works with I2C1

TDK
Guru

Okay, well it's hard to debug with the information you've provided. Did you look at how the code is different between them? I can't debug what I cannot see. There's an explanation. Could be a solder bridge or other hardware related bug, could be any number of things.

If you feel a post has answered your question, please click "Accept as Solution".
AKunc.1
Associate II

Please tell me what kind of debug information do you need to help me?

AKunc.1
Associate II

Here is the initialization code

static void MX_I2C1_Init(void)

{

 /* USER CODE BEGIN I2C1_Init 0 */

 /* USER CODE END I2C1_Init 0 */

 /* USER CODE BEGIN I2C1_Init 1 */

 /* USER CODE END I2C1_Init 1 */

 hi2c1.Instance = I2C1;

 hi2c1.Init.ClockSpeed = 100000;

 hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2;

 hi2c1.Init.OwnAddress1 = 0;

 hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;

 hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;

 hi2c1.Init.OwnAddress2 = 0;

 hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;

 hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;

 if (HAL_I2C_Init(&hi2c1) != HAL_OK)

 {

  Error_Handler();

 }

 /* USER CODE BEGIN I2C1_Init 2 */

 /* USER CODE END I2C1_Init 2 */

}

TDK
Guru

Initialization code seems fine.

Compare the I2C registers between the working I2C2 and the nonworking I2C1.

Possibly make the I2C1 pins GPIO and see if you can toggle them okay. Measure voltages or use a scope to confirm.

If you feel a post has answered your question, please click "Accept as Solution".