欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

SENSIRION SCD30 二氧化碳传感器测量数据转换

程序员文章站 2024-02-26 22:49:40
...

硬件:Nordic nRF52840 SoC, SENSIRION SCD30

软件: Nordic SDK V15.2, Keil V5.23


SCD30 I2C 读取测量值命令, 0x0300

SENSIRION SCD30 二氧化碳传感器测量数据转换

SENSIRION SCD30 二氧化碳传感器测量数据转换

SENSIRION SCD30 二氧化碳传感器测量数据转换


参考代码

float	CO2Concentration,realValueOfTemperature,realValueOfHumidity;
uint32_t tempCO2,tempTemp,tempHumi;
uint8_t	buffer[4];
buffer[0] = 0x43;
buffer[1] = 0xDB;
buffer[2] = 0x8C;
buffer[3] = 0x2E;
tempCO2 = (uint32_t) ((((uint32_t)buffer[0]) << 24) | 
			(((uint32_t)buffer[1]) << 16) | 
			(((uint32_t)buffer[2]) << 8) | 
			((uint32_t)buffer[0]));
	
CO2Concentration = * (float *) &tempCO2;
NRF_LOG_INFO("CO2: " NRF_LOG_FLOAT_MARKER " ppm. \r\n", NRF_LOG_FLOAT(CO2Concentration));


buffer[0] = 0x41;
buffer[1] = 0xD9;
buffer[2] = 0xE7;
buffer[3] = 0xFF;
tempTemp = (uint32_t) ((((uint32_t)buffer[0]) << 24) | 
			(((uint32_t)buffer[1]) << 16) | 
			(((uint32_t)buffer[2]) << 8) | 
			((uint32_t)buffer[0]));
	
realValueOfTemperature = * (float *) &tempTemp;
NRF_LOG_INFO("Temperature: " NRF_LOG_FLOAT_MARKER "Degree C. \r\n", NRF_LOG_FLOAT(realValueOfTemperature));


buffer[0] = 0x42;
buffer[1] = 0x43;
buffer[2] = 0x3A;
buffer[3] = 0x1B;
tempHumi = (uint32_t) ((((uint32_t)buffer[0]) << 24) | 
			(((uint32_t)buffer[1]) << 16) | 
			(((uint32_t)buffer[2]) << 8) | 
			((uint32_t)buffer[0]));
	
realValueOfHumidity = * (float *) &tempHumi;
NRF_LOG_INFO("Humidity: " NRF_LOG_FLOAT_MARKER "%%. \r\n", NRF_LOG_FLOAT(realValueOfHumidity));