cancel
Showing results for 
Search instead for 
Did you mean: 

Challeng with I2C1 and I2C2

NASI
Senior

Hello,

I am working with a costumer board using STM32F105. There are some LED drivers working I2C1 and I2c2.

Configuration for serial interfaces is:

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

}

/* I2C2 init function */

void MX_I2C2_Init(void)

{

 /* USER CODE BEGIN I2C2_Init 0 */

 /* USER CODE END I2C2_Init 0 */

 /* USER CODE BEGIN I2C2_Init 1 */

 /* USER CODE END I2C2_Init 1 */

 hi2c2.Instance = I2C2;

 hi2c2.Init.ClockSpeed = 100000;

 hi2c2.Init.DutyCycle = I2C_DUTYCYCLE_2;

 hi2c2.Init.OwnAddress1 = 0;

 hi2c2.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;

 hi2c2.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;

 hi2c2.Init.OwnAddress2 = 0;

 hi2c2.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;

 hi2c2.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;

 if (HAL_I2C_Init(&hi2c2) != HAL_OK)

 {

  Error_Handler();

 }

 /* USER CODE BEGIN I2C2_Init 2 */

 /* USER CODE END I2C2_Init 2 */

}

HW connections should be correct, because I am able to turn all LEDs which they configured in I2C1 and I2C2. But after some tries, I miss I2C1 and ErrorCode 32 (Timeout error) show up.

For I2C1, the errorcode is 32, and for I2C2 there is no error.

I am using 10ms for timeout for both I2C's, and it doesn't help if I put more timeout.

I am using following function to write the value on serial interface with related data:

void WriteRegister(HandleTypeDef* handle, uint8_t register_address, uint8_t value)

{

uint8_t buf[2];

buf[0] = register_address;

buf[1] = value;

HAL_I2C_Master_Transmit(handle->Init.I2C_Bus, handle->Init.I2C_Device_Address, buf, 2, handle->Init.I2C_Transmit_Timeout_Milliseconds);

}

Any idea?

Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
NASI
Senior

Thank you @TDK​ and @Amel NASRI​ .

Some HW issues have been found for the LED drivers circuit. It seems to be work fine now. I need to test with other prototypes as well.

View solution in original post

4 REPLIES 4
TDK
Guru

Sounds like a hardware issue.

Which line within HAL_I2C_Master_Transmit produces the timeout?

Do you have a logic analyzer to show the SDA/SCL lines?

Are there pullups on both lines?

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

Hi @NASI​ ,

Besides to proposals from @TDK​ , I suggest you to have a look to the product errata sheet.

Several known limitations on the I2C of STM32F1 are described on this document.

-Amel

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

NASI
Senior

Thank you @TDK​ and @Amel NASRI​ .

Some HW issues have been found for the LED drivers circuit. It seems to be work fine now. I need to test with other prototypes as well.

Good to know that you identified the root cause of your issue.

I mark your reply as best answer. In case you have new questions, don't hesitate to create new inputs.

-Amel

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.