[Silicon Labs Development Kit Review] +Si7021 Temperature and Humidity Sensor Detection
[Copy link]
This post was last edited by yin_wu_qing on 2021-9-6 09:50
As mentioned in the previous post, the development board integrates the Si7021 temperature and humidity sensor, which uses the IIC interface to communicate with the MCU. Through the official data sheet, we can understand the packaging, characteristics, and detailed communication protocol of this sensor. Several important information points are shared as follows:
The circuit connection of Si7021 sensor on EFM32PG22 development board can refer to the circuit schematic diagram
Similarly, Si7021 and the ambient light sensor (VEML6035) and Hall effect sensor (Si7210) shared earlier are all connected to the IIC bus, SDA is connected to the PD02 pin, SCL is connected to the PD03 pin, and the enable pin is PC06. In "Simplicity Studio IDE", create an RTOS basic project. Here, the template from the previous issue is used. You only need to install the corresponding configuration interface.
After completing the construction of the above components, include the header file of the Si7021 sensor in the task processing source file
Now open the "sl_si70xx.h" file and you will find that the official has provided a reference example. The user only needs to put the reference example function in the task processing function to be called.
Print out the collected Data value using the floating point data type, then compile and download, open the serial port debugging assistant, and then gently place your finger on the Si7021 sensor. You can clearly see that the temperature and humidity values will increase accordingly; if you remove your finger, the temperature and humidity values will slowly return to the indoor temperature and humidity values. This shows that the Si7021 sensor on the development board is very sensitive and the collected data is very accurate.
#include <stdio.h>
#include "FreeRTOS.h"
#include "task.h"
#include "sl_i2cspm.h"
#include "em_cmu.h"
#include "sl_i2cspm_sensor_config.h"
#include "sl_veml6035.h"
#include "sl_si7210.h"
#include "sl_si70xx.h"
#ifndef TOOGLE_DELAY_MS
#define TOOGLE_DELAY_MS 25
#endif
#ifndef Envir_Hall_STACK_SIZE
#define Envir_Hall_STACK_SIZE configMINIMAL_STACK_SIZE
#endif
#ifndef EXAMPLE_USE_STATIC_ALLOCATION
#define EXAMPLE_USE_STATIC_ALLOCATION 0
#endif
static void Envir_Hall_test_task(void *arg);
sl_i2cspm_t *sl_i2cspm_sensor = SL_I2CSPM_SENSOR_PERIPHERAL;
void Envir_Hall_test_init(void)
{
TaskHandle_t xHandle = NULL;
BaseType_t xReturned = pdFAIL;
#if (EXAMPLE_USE_STATIC_ALLOCATION == 1)
static StaticTask_t xTaskBuffer;
static StackType_t xStack[Envir_Hall_STACK_SIZE];
#else
xReturned = xTaskCreate(Envir_Hall_test_task,
"Envir_Hall_test task",
Envir_Hall_STACK_SIZE,
( void * ) NULL,
tskIDLE_PRIORITY + 4,
&xHandle);
EFM_ASSERT(xReturned == pdPASS);
#endif
}
static void Envir_Hall_test_task(void *arg)
{
int32_t temp_data; //温度值
uint32_t rh_data; //湿度值
uint8_t fw_data;
(void)&arg;
sl_si70xx_init(sl_i2cspm_sensor,SI7021_ADDR);
sl_si70xx_get_firmware_revision(sl_i2cspm_sensor,SI7021_ADDR,&fw_data);
printf("si7021's FW Version:%d\r\n",fw_data);
while(1)
{
sl_si70xx_measure_rh_and_temp(sl_i2cspm_sensor,SI7021_ADDR,&rh_data,&temp_data);
printf("\n");
printf("hum=%f tem=%f\r\n",rh_data/1000.0,temp_data/1000.0);
}
}
|