Skip to main content
SF49ers
Associate II
November 22, 2018
Solved

Can't get STM32F10x and CubeMX HAL I2C driver to work

  • November 22, 2018
  • 1 reply
  • 697 views

Hello,

i try to get a most simple I2C driver to work. So, i setup I2C1 with CubeMX and select code generation.

In the resulting main.c, all i have to do is to add something like that:

 /* USER CODE BEGIN WHILE */
 while (1)
 {
	uint8_t value = 0;
 
	for (uint32_t i = 0; i < 100000; i++)
		asm("NOP");
 
	HAL_I2C_Master_Transmit(&hi2c1, (uint16_t)(0x27 << 1), (uint8_t*)&value, 1, 100);

This should be enough to see anything an my data logger, shouldn't it?

But all i see is SCL and SDA staying hijgh - no glitch no change.

Before you ask: The hardware is working as expected. I have this same device running with a Standard Peripheral Library driver (where i did hardware initialization by myself) wijthout problems.

So, what do i miss in this CubeMX project?

Best regards,

SF49ers

This topic has been closed for replies.
Best answer by SF49ers

CubeMX generates the initialization code for the modules and so it does for I2C. The MX_I2C1_Init() is found in the main.c. But in my case, it was not added by CubeMX to the main function and so the initialization took not place. Adding it by hand does the job.

This is not a feature, is it?

1 reply

SF49ers
SF49ersAuthorAnswer
Associate II
November 22, 2018

CubeMX generates the initialization code for the modules and so it does for I2C. The MX_I2C1_Init() is found in the main.c. But in my case, it was not added by CubeMX to the main function and so the initialization took not place. Adding it by hand does the job.

This is not a feature, is it?