cancel
Showing results for 
Search instead for 
Did you mean: 

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

SF49ers
Associate

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

1 ACCEPTED SOLUTION

Accepted Solutions
SF49ers
Associate

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?

View solution in original post

1 REPLY 1
SF49ers
Associate

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?