20#define SCD41_ADDR (0x62 << 1)
21#define SPS30_ADDR (0x69 << 1)
24#define SCD41_CMD_START_PERIODIC 0x21b1
25#define SCD41_CMD_START_LOW_POWER_PERIODIC 0x21ac
26#define SCD41_CMD_START_SINGLE_SHOT 0x219D
28#define SCD41_CMD_START SCD41_CMD_START_PERIODIC
32#define SCD41_CMD_STOP_PERIODIC 0x3f86
33#define SCD41_CMD_SET_ALTITUDE 0x2427
34#define SCD41_CMD_READ_MEAS 0xec05
35#define SCD41_CMD_GET_DATA_READY 0xe4b8
36#define SCD41_CMD_REINIT 0x3646
48 tx[0] = (uint8_t) (cmd >> 8);
49 tx[1] = (uint8_t) (cmd & 0xFF);
50 tx[2] = (uint8_t) (val >> 8);
51 tx[3] = (uint8_t) (val & 0xFF);
53 return HAL_I2C_Master_Transmit(hi2c,
SCD41_ADDR, tx, 5, 100);
56static HAL_StatusTypeDef
scd41_onOff(I2C_HandleTypeDef *hi2c, uint16_t onOff)
58 HAL_StatusTypeDef status = HAL_ERROR;
61 cmd[0] = (onOff >> 8);
62 cmd[1] = (onOff & 0xFF);
63 status = HAL_I2C_Master_Transmit(hi2c,
SCD41_ADDR, cmd, 2, HAL_MAX_DELAY);
70int8_t
scd41_Is(I2C_HandleTypeDef *hi2c, int8_t tryInit)
77HAL_StatusTypeDef
scd41_On(I2C_HandleTypeDef *hi2c)
79 HAL_StatusTypeDef status = HAL_ERROR;
113 if ((ret = HAL_I2C_Master_Transmit(hi2c,
SCD41_ADDR, cmd, 2, HAL_MAX_DELAY)) != HAL_OK)
145 HAL_StatusTypeDef status = HAL_ERROR;
157 if ((status = HAL_I2C_Master_Transmit(hi2c,
SCD41_ADDR, cmd, 2, 100)) != HAL_OK)
162 if ((status = HAL_I2C_Master_Receive(hi2c,
SCD41_ADDR, buf, 3, 100)) != HAL_OK)
182 status = ((dataReady & 0x07FF) != 0) ? HAL_OK : HAL_BUSY;
194 if (status == HAL_OK)
203 if ((status = HAL_I2C_Master_Transmit(hi2c,
SCD41_ADDR, cmd, 2, HAL_MAX_DELAY)) != HAL_OK)
207 if ((status = HAL_I2C_Master_Receive(hi2c,
SCD41_ADDR, buf, 9, HAL_MAX_DELAY)) != HAL_OK)
219 _scd41Data.Co2 = (float) ((uint16_t) ((buf[0] << 8) | buf[1]));
220 _scd41Data.Temperature = -45.0f + 175.0f * (float) ((buf[3] << 8) | buf[4]) / 65536.0f;
221 _scd41Data.Humidity = 100.0f * (float) ((buf[6] << 8) | buf[7]) / 65536.0f;
This file contains all the function prototypes for the i2c.c file.
HAL_StatusTypeDef I2C_IsDeviceReadyMT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint32_t Trials, uint32_t Timeout)
Wrapper around HAL_I2C_IsDeviceReady() that recovers from a busy bus. If the HAL I2C bus is in a BUSY...
#define PRIf_02D(fData)
Expands to integer and fractional arguments for use with PRIf_02. Splits a float/double into the inte...
#define PRIf_02
printf format string for printing a float/double as integer with 2 decimal places....
mems_MainBlock_t _memsMainBlock
Global instance of the main flash control block; loaded by mems_ReadMainBlock().
HAL_StatusTypeDef mems_WriteMainBlock()
writing the main block on flash. The main block is stored on address 0
systemParams_t _systemParams
uint8_t systemParams_CalculateCrc(uint8_t *data, uint8_t len)
Calculate a CRC-8 checksum (Sensirion polynomial) over a byte buffer. Used to validate sensor I2C res...
#define SCD41_CMD_STOP_PERIODIC
HAL_StatusTypeDef scd41_IsDataReady(I2C_HandleTypeDef *hi2c)
check if data is available
#define SCD41_CMD_READ_MEAS
static HAL_StatusTypeDef scd41_onOff(I2C_HandleTypeDef *hi2c, uint16_t onOff)
#define SCD41_CMD_SET_ALTITUDE
#define SCD41_CMD_GET_DATA_READY
HAL_StatusTypeDef scd41_Off(I2C_HandleTypeDef *hi2c)
stop reading
void scd41_LogData(char *buf)
log data to buffer
HAL_StatusTypeDef scd41_Init(I2C_HandleTypeDef *hi2c)
initialization of sensor sdc41
HAL_StatusTypeDef scd41_Read(I2C_HandleTypeDef *hi2c)
read value from sensor
static HAL_StatusTypeDef scd41_WriteWithCRC(I2C_HandleTypeDef *hi2c, uint16_t cmd, uint16_t val)
HAL_StatusTypeDef scd41_On(I2C_HandleTypeDef *hi2c)
start reading - turn on sensor, reading mode can be: SCD41_CMD_START_PERIODIC - every 5s - this is pr...
int8_t scd41_Is(I2C_HandleTypeDef *hi2c, int8_t tryInit)
check if CO2 sensor is present
scd41_t _scd41Data
Live measurement data from the SCD41 sensor; updated by scd41_Read().
scd41_t _bck_scd41Data
Snapshot copy of the last completed measurement; used for LoRaWAN transmission.
Measurement data produced by the SCD41 CO2 / temperature / humidity sensor. Populated by scd41_Read()...
void HAL_Delay(__IO uint32_t Delay)