L14-Click 1.0
STM32WLE5CC LoRaWAN Sensor Platform
Loading...
Searching...
No Matches
scd41.c File Reference
#include "scd41.h"
#include "i2c.h"
#include "utils/mydefs.h"
#include "mymems.h"
#include "mysensors_base.h"
#include <stdio.h>
Include dependency graph for scd41.c:

Go to the source code of this file.

Macros

#define SCD41_ADDR   (0x62 << 1)
#define SPS30_ADDR   (0x69 << 1)
#define SCD41_CMD_START_PERIODIC   0x21b1
#define SCD41_CMD_START_LOW_POWER_PERIODIC   0x21ac
#define SCD41_CMD_START_SINGLE_SHOT   0x219D
#define SCD41_CMD_START   SCD41_CMD_START_PERIODIC
#define SCD41_CMD_STOP_PERIODIC   0x3f86
#define SCD41_CMD_SET_ALTITUDE   0x2427
#define SCD41_CMD_READ_MEAS   0xec05
#define SCD41_CMD_GET_DATA_READY   0xe4b8
#define SCD41_CMD_REINIT   0x3646

Functions

static HAL_StatusTypeDef scd41_WriteWithCRC (I2C_HandleTypeDef *hi2c, uint16_t cmd, uint16_t val)
static HAL_StatusTypeDef scd41_onOff (I2C_HandleTypeDef *hi2c, uint16_t onOff)
int8_t scd41_Is (I2C_HandleTypeDef *hi2c, int8_t tryInit)
 
  • check if CO2 sensor is present

HAL_StatusTypeDef scd41_On (I2C_HandleTypeDef *hi2c)
 start reading - turn on sensor, reading mode can be: SCD41_CMD_START_PERIODIC - every 5s - this is probably most accurate SCD41_CMD_START_LOW_POWER_PERIODIC - every 30s
HAL_StatusTypeDef scd41_Off (I2C_HandleTypeDef *hi2c)
 stop reading
HAL_StatusTypeDef scd41_Init (I2C_HandleTypeDef *hi2c)
 initialization of sensor sdc41
HAL_StatusTypeDef scd41_IsDataReady (I2C_HandleTypeDef *hi2c)
 check if data is available
HAL_StatusTypeDef scd41_Read (I2C_HandleTypeDef *hi2c)
 read value from sensor
void scd41_LogData (char *buf)
 log data to buffer

Variables

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.
static int8_t _isScd41 = 0

Macro Definition Documentation

◆ SCD41_ADDR

#define SCD41_ADDR   (0x62 << 1)

Definition at line 20 of file scd41.c.

Referenced by scd41_Init(), scd41_IsDataReady(), scd41_onOff(), scd41_Read(), and scd41_WriteWithCRC().

◆ SCD41_CMD_GET_DATA_READY

#define SCD41_CMD_GET_DATA_READY   0xe4b8

Definition at line 35 of file scd41.c.

Referenced by scd41_IsDataReady().

◆ SCD41_CMD_READ_MEAS

#define SCD41_CMD_READ_MEAS   0xec05

Definition at line 34 of file scd41.c.

Referenced by scd41_Read().

◆ SCD41_CMD_REINIT

#define SCD41_CMD_REINIT   0x3646

Definition at line 36 of file scd41.c.

Referenced by scd41_Init().

◆ SCD41_CMD_SET_ALTITUDE

#define SCD41_CMD_SET_ALTITUDE   0x2427

Definition at line 33 of file scd41.c.

Referenced by scd41_Init().

◆ SCD41_CMD_START

#define SCD41_CMD_START   SCD41_CMD_START_PERIODIC

Definition at line 28 of file scd41.c.

Referenced by scd41_On().

◆ SCD41_CMD_START_LOW_POWER_PERIODIC

#define SCD41_CMD_START_LOW_POWER_PERIODIC   0x21ac

Definition at line 25 of file scd41.c.

◆ SCD41_CMD_START_PERIODIC

#define SCD41_CMD_START_PERIODIC   0x21b1

Definition at line 24 of file scd41.c.

◆ SCD41_CMD_START_SINGLE_SHOT

#define SCD41_CMD_START_SINGLE_SHOT   0x219D

Definition at line 26 of file scd41.c.

◆ SCD41_CMD_STOP_PERIODIC

#define SCD41_CMD_STOP_PERIODIC   0x3f86

Definition at line 32 of file scd41.c.

Referenced by scd41_Off().

◆ SPS30_ADDR

#define SPS30_ADDR   (0x69 << 1)

Definition at line 21 of file scd41.c.

Function Documentation

◆ scd41_Init()

HAL_StatusTypeDef scd41_Init ( I2C_HandleTypeDef * hi2c)

initialization of sensor sdc41

Return values
HAL_OK- sensor is present, HAL_ERROR - error

Definition at line 99 of file scd41.c.

References _isScd41, _systemParams, HAL_Delay(), I2C_IsDeviceReadyMT(), SCD41_ADDR, SCD41_CMD_REINIT, SCD41_CMD_SET_ALTITUDE, scd41_Off(), and scd41_WriteWithCRC().

Referenced by scd41_Is().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scd41_Is()

int8_t scd41_Is ( I2C_HandleTypeDef * hi2c,
int8_t tryInit )

  • check if CO2 sensor is present

Parameters
tryInit- in case sensor is not yet initialized, 1 - attempt to initialize again, 0 - no
Return values
1- is present, 0 - is not

Definition at line 70 of file scd41.c.

References _isScd41, and scd41_Init().

Here is the call graph for this function:

◆ scd41_IsDataReady()

HAL_StatusTypeDef scd41_IsDataReady ( I2C_HandleTypeDef * hi2c)

check if data is available

Return values
HAL_OK- data is available, can be read, HAL_BUSY - data not yet available, HAL_ERROR - error

Definition at line 143 of file scd41.c.

References _isScd41, HAL_Delay(), SCD41_ADDR, SCD41_CMD_GET_DATA_READY, and systemParams_CalculateCrc().

Referenced by scd41_Read().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scd41_LogData()

void scd41_LogData ( char * buf)

log data to buffer

Definition at line 228 of file scd41.c.

References _scd41Data, PRIf_02, and PRIf_02D.

◆ scd41_Off()

HAL_StatusTypeDef scd41_Off ( I2C_HandleTypeDef * hi2c)

stop reading

Definition at line 94 of file scd41.c.

References SCD41_CMD_STOP_PERIODIC, and scd41_onOff().

Referenced by scd41_Init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scd41_On()

HAL_StatusTypeDef scd41_On ( I2C_HandleTypeDef * hi2c)

start reading - turn on sensor, reading mode can be: SCD41_CMD_START_PERIODIC - every 5s - this is probably most accurate SCD41_CMD_START_LOW_POWER_PERIODIC - every 30s

Definition at line 77 of file scd41.c.

References _isScd41, _memsMainBlock, _scd41Data, mems_WriteMainBlock(), SCD41_CMD_START, and scd41_onOff().

Here is the call graph for this function:

◆ scd41_onOff()

HAL_StatusTypeDef scd41_onOff ( I2C_HandleTypeDef * hi2c,
uint16_t onOff )
static

Definition at line 56 of file scd41.c.

References _isScd41, and SCD41_ADDR.

Referenced by scd41_Off(), and scd41_On().

Here is the caller graph for this function:

◆ scd41_Read()

HAL_StatusTypeDef scd41_Read ( I2C_HandleTypeDef * hi2c)

read value from sensor

Return values
HAL_OK- have data, HAL_BUSY - data not yet available, HAL_ERROR - error

Definition at line 190 of file scd41.c.

References _scd41Data, HAL_Delay(), SCD41_ADDR, SCD41_CMD_READ_MEAS, scd41_IsDataReady(), and systemParams_CalculateCrc().

Here is the call graph for this function:

◆ scd41_WriteWithCRC()

HAL_StatusTypeDef scd41_WriteWithCRC ( I2C_HandleTypeDef * hi2c,
uint16_t cmd,
uint16_t val )
static

Definition at line 45 of file scd41.c.

References SCD41_ADDR, and systemParams_CalculateCrc().

Referenced by scd41_Init().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ _bck_scd41Data

scd41_t _bck_scd41Data = {}

Snapshot copy of the last completed measurement; used for LoRaWAN transmission.

Definition at line 40 of file scd41.c.

Referenced by sensors_CayennelFromBckData(), sensors_CopyToBck(), sensors_ReadToBckFromDataBlock(), and sensors_WriteFromBckToDataBlock().

◆ _isScd41

int8_t _isScd41 = 0
static

Definition at line 42 of file scd41.c.

Referenced by scd41_Init(), scd41_Is(), scd41_IsDataReady(), scd41_On(), and scd41_onOff().

◆ _scd41Data

scd41_t _scd41Data = {}

Live measurement data from the SCD41 sensor; updated by scd41_Read().

Definition at line 39 of file scd41.c.

Referenced by scd41_LogData(), scd41_On(), scd41_Read(), and sensors_CopyToBck().