点击文件名下载附件
传感器我就不多介绍,详细的参数请看规格书,下面我们看一下原理图:
SI7021是用IIC通信的,IIC上面挂了好几个传感器。
通过TS3A4751连接在PC04 PC05 IO口上。
下图简单的说明,和Si7021如何连接到EFR32MG24。
下在看代码:
IIC的初始化:
I2C_TransferReturn_TypeDef ret;
uint8_t cmdReadId2[2] = SI7021_CMD_READ_ID_BYTE2;
uint8_t deviceId[8];
// Wait for sensor to become ready
sl_sleeptimer_delay_millisecond(80);
// Check for device presence and compare device ID
ret = SI7021_transaction(I2C_FLAG_WRITE_READ, cmdReadId2, 2, deviceId, 8);
// Make sure transfer was successful
EFM_ASSERT(ret == i2cTransferDone);
// Check the Received Device ID
EFM_ASSERT(deviceId[0] == SI7021_DEVICE_ID);
// Initialize LED PWM module
initialise_temp_limits();
// Initialize Periodic timer
initialise_timer();
// stdout is redirected to VCOM in project configuration
printf("Welcome to the I2CSPM example application\r\n");
if (local_read_sensor_data) {
// Measure the current humidity and temperature
SI7021_measure(&relative_humidity, &temperature);
// Print the current humidity and temperature to vcom
printf("\r\n");
printf("Relative Humidity = %ld%%\r\n", relative_humidity);
printf("Temperature = %ld C\r\n", temperature);
// Set appropriate LEDs (led0 or 1) based on temperature
set_leds(temperature);
// Reset the flag
local_read_sensor_data = false;
sl_atomic_store(read_sensor_data, local_read_sensor_data);