cancel
Showing results for 
Search instead for 
Did you mean: 

An absolute beginner needs help programming peripheral devices with the STM32Cube

Mick P. F.
Senior

Hello ,

I'm using the latest STM32Cube with NUCLEO144-H743ZI2 board.

I am a complete beginner with using the STM32 and STM32Cube. I came from the ESP32 world, where everything was relatively easy. Through numerous attempts, I can now handle the STM32Cube (especially the STM32CubeMX), even if some terms that appear there are still unknown to me.

At the beginning I set the goal to get the TSL2591 sensor running. Communication with this component takes place via the I2C bus (I2C1).

In the STM32CubeMX I have specified that the pins PB8 and PB9 should be used for SCL and SDA respectively. In the generated code I cannot see this definition anywhere! That is my first problem.

When I debug the code, calling the procedure "tsl2591_initialize()" leads to calling the function "I2C_IsAcknowledgeFailed()" in the file "stm32h7xx_hal_i2c.c", lines 6377ff. The first query of the flag "I2C_FLAG_AF" says that this flag is set. The execution of the following loop "while (__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_STOPF) == RESET)" is exited, but the code afterwards leads to the return with error. I can't recognize the reason for this. Probably something is missing in my code.

What am I doing wrong?

Can anybody help me to get this code running?

I've put the entire project in the attachment.

Thanks in Advance,

Michael

4 REPLIES 4
Khouloud ZEMMELI
ST Employee

Hi @Mick P. F.​ 

I'll answer you on the first question linked to CubeMX and configuration pins.

In fact, the code of GPIO Configuration is generated under stm32xxx_hal_msp.c file, you can find there all pins configured for each IP used.

Hope this information helped you, Khouloud

Mick P. F.
Senior

Hello Khouloud,

Many thanks for your tip!

Now I know where to find the initialization/configuration code, but that doesn't help me to solve the runtime problem.

KnarfB
Principal III

It looks like the device doesn't answer your request on the bus. The HAL API requests that "The device 7 bits address value in datasheet must be shifted to the left before calling the interface", see HAL_I2C_Mem_Read description.

Mick P. F.
Senior

Hello KnarfB,

That was my (first) mistake... I've seen this before, but I didn't think anything of it.

Many thanks!