2020-05-05 07:46 AM
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/
2020-05-05 09:17 AM
Is the I2C1 bus in use by something else? Is a misbehaving slave holding SCL low?
2020-05-05 10:56 AM
Bus is free without anyone. SCL and SDA are with pull up resistors 4.7k Ohm
2020-05-05 11:16 AM
The fact is that I checked this code and initialization on STM32F205VEt6 it does not work, but on STM32F205REt6 it works with I2C1
2020-05-05 11:19 AM
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.
2020-05-05 10:42 PM
Please tell me what kind of debug information do you need to help me?
2020-05-05 11:08 PM
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 */
}
2020-05-06 06:03 AM
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.