[NUCLEO-WBA52CG STM32 wireless product family new series] +2, hardware i2c driver temperature and humidity sensor SHT40
[Copy link]
This post was last edited by dql2016 on 2023-7-30 22:04
I have a Grove SHT40 sensor module, as shown in the figure below. I use it to learn how to use the STM32WBA52CG hardware I2C.
SHT40 is a digital temperature and humidity sensor with an accuracy of up to ±1.8% / max. ±3.5% RH. The main parameters are as follows:
humidity |
Typical relative humidity accuracy |
1.8 |
%RH |
|
Operating relative humidity range |
0 - 100 |
%RH |
|
Response time (τ63%) |
4 |
s |
|
Calibration Certificate |
Factory Calibration |
|
|
temperature |
Typical temperature accuracy |
0.2 |
°C |
|
Operating temperature range |
-40 - 125 |
°C |
|
Response time (τ63%) |
2 |
s |
|
Normal |
Supply voltage |
1.08 - 3.6 |
V |
|
Average supply current |
0.4 |
uA |
|
interface |
IC |
|
|
Dimensions (L x W x H) |
1.5 x 1.5 x 0.5 |
mm |
|
Packing size |
2500, 10000 |
pcs (T&R) |
|
Official information
https://sensirion.com/cn/products/product-catalog/SHT40/
The official driver reference download is provided
First, use Stm32cubemx to create a project based on the development board. The advantage of creating a project based on the development board is that the onboard peripherals such as LEDs and buttons are initialized and configured for you:
Open the serial port configuration to facilitate printing logs:
Turn on the hardware I2C. The parameter settings are very simple. You can just use the default ones:
After configuration, generate the project.
Next, refer to the schematic diagram to determine the location of the I2C1 pin:
Connect the lines:
Unzip the driver package downloaded from the official website of Sensirion, and then copy the corresponding files to the project directory of stm32:
Copy the reference driver and replace it:
Create a new group in keil and add these files:
Remove the initialization in the driver abstraction layer, because stm32cubemx has already generated the i2c driver:
The main function calls the test code:
Add printf printing support to the serial port driver:
Final result:
Attach the source package:
|