2023-12-28 01:47 AM - last edited on 2023-12-28 03:25 AM by SofLit
Hi
I am a hardware design base person, it's been a while I wrote the code.
I have one STM NUCLEO-F401RE board and one sht3x i2c sensor. I wonder how to make them working (at least print sensor information via UART serial port). I see some source code like sht3x.c and sht3x.h are provided on Github(https://github.com/henriheimann/stm32-hal-sht3x). I follow the instruction to cpoy them into INC and SRC in STM32CubeIDE project However, I encounter lots error messages while building the code. Could anyone help to have a step-by-step walkthrough about how to bring it up?
Solved! Go to Solution.
2023-12-28 05:08 AM - edited 2023-12-29 01:43 PM
Sensirion humidity meter... everyone seems to make drones these days ((
@pcpeng Basically if you use CubeIDE, you can take any example project for UART and example for I2C in master mode (provided in the STM32F4 "Cube" package for your board). The standard I2C 400 KHz mode should work well. Build them separately; make sure that printing to UART works and communication with i2c device works (as a hardware person, use your scope and logic analyzer...). Then combine both projects together into a program that talks to the i2c sensor and prints to the UART.
Unfortunately Eclipse based IDE is not very friendly to beginner, it takes time to find how to add source and include files. Please refer to the user guide if nothing else helps.
The linked source files are for a different STM32 family, L0. Delete everything related to STM32L0 and include instead stm32f4xx_hal.h. To make it simple, include "main.h" from the Cube i2c example.
2023-12-28 02:04 AM
In sht3x.h, check if you've already included the file stm32f401xe.h in the list here:
#if (defined STM32L011xx) || (defined STM32L021xx) || \
(defined STM32L031xx) || (defined STM32L041xx) || \
(defined STM32L051xx) || (defined STM32L052xx) || (defined STM32L053xx) || \
(defined STM32L061xx) || (defined STM32L062xx) || (defined STM32L063xx) || \
(defined STM32L071xx) || (defined STM32L072xx) || (defined STM32L073xx) || \
(defined STM32L081xx) || (defined STM32L082xx) || (defined STM32L083xx)
#include "stm32l0xx_hal.h"
#elif defined (STM32L412xx) || defined (STM32L422xx) || \
defined (STM32L431xx) || (defined STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || defined (STM32L443xx) || \
defined (STM32L451xx) || defined (STM32L452xx) || defined (STM32L462xx) || \
defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || \
defined (STM32L496xx) || defined (STM32L4A6xx) || \
defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx)
#include "stm32l4xx_hal.h"
#else
#error Platform not implemented
#endif
2023-12-28 05:08 AM - edited 2023-12-29 01:43 PM
Sensirion humidity meter... everyone seems to make drones these days ((
@pcpeng Basically if you use CubeIDE, you can take any example project for UART and example for I2C in master mode (provided in the STM32F4 "Cube" package for your board). The standard I2C 400 KHz mode should work well. Build them separately; make sure that printing to UART works and communication with i2c device works (as a hardware person, use your scope and logic analyzer...). Then combine both projects together into a program that talks to the i2c sensor and prints to the UART.
Unfortunately Eclipse based IDE is not very friendly to beginner, it takes time to find how to add source and include files. Please refer to the user guide if nothing else helps.
The linked source files are for a different STM32 family, L0. Delete everything related to STM32L0 and include instead stm32f4xx_hal.h. To make it simple, include "main.h" from the Cube i2c example.