LibDriver SCD4X
Loading...
Searching...
No Matches
driver_scd4x.c File Reference

driver scd4x source file More...

#include "driver_scd4x.h"
Include dependency graph for driver_scd4x.c:

Go to the source code of this file.

Macros

#define CHIP_NAME   "Sensirion SCD4X"
 chip information definition
#define MANUFACTURER_NAME   "Sensirion"
#define SUPPLY_VOLTAGE_MIN   2.40f
#define SUPPLY_VOLTAGE_MAX   5.50f
#define MAX_CURRENT   205.0f
#define TEMPERATURE_MIN   -10.0f
#define TEMPERATURE_MAX   60.0f
#define DRIVER_VERSION   1000
#define SCD4X_ADDRESS   (0x62 << 1)
 chip address definition
#define SCD4X_COMMAND_START_PERIODIC   0x21B1U
 chip command definition
#define SCD4X_COMMAND_READ   0xEC05U
#define SCD4X_COMMAND_STOP_PERIODIC   0x3F86U
#define SCD4X_COMMAND_SET_TEMPERATURE_OFFSET   0x241DU
#define SCD4X_COMMAND_GET_TEMPERATURE_OFFSET   0x2318U
#define SCD4X_COMMAND_SET_SENSOR_ALTITUDE   0x2427U
#define SCD4X_COMMAND_GET_SENSOR_ALTITUDE   0x2322U
#define SCD4X_COMMAND_SET_AMBIENT_PRESSURE   0xE000U
#define SCD4X_COMMAND_GET_AMBIENT_PRESSURE   0xE000U
#define SCD4X_COMMAND_PERFORM_FORCED_RECALIBRATION   0x362FU
#define SCD4X_COMMAND_SET_AUTO_SELF_CALIBRATION   0x2416U
#define SCD4X_COMMAND_GET_AUTO_SELF_CALIBRATION   0x2313U
#define SCD4X_COMMAND_START_LOW_POWER_PERIODIC   0x21ACU
#define SCD4X_COMMAND_GET_DATA_READY_STATUS   0xE4B8U
#define SCD4X_COMMAND_PERSIST_SETTINGS   0x3615U
#define SCD4X_COMMAND_GET_SERIAL_NUMBER   0x3682U
#define SCD4X_COMMAND_PERFORM_SELF_TEST   0x3639U
#define SCD4X_COMMAND_PERFORM_FACTORY_RESET   0x3632U
#define SCD4X_COMMAND_REINIT   0x3646U
#define SCD4X_COMMAND_MEASURE_SINGLE_SHOT   0x219DU
#define SCD4X_COMMAND_MEASURE_SINGLE_SHOT_RHT_ONLY   0x2196U
#define SCD4X_COMMAND_POWER_DOWN   0x36E0U
#define SCD4X_COMMAND_WAKE_UP   0x36F6U
#define SCD4X_COMMAND_SET_AUTO_SELF_CALIBRATION_INIT_PERIOD   0x2445U
#define SCD4X_COMMAND_GET_AUTO_SELF_CALIBRATION_INIT_PERIOD   0x2340U
#define SCD4X_COMMAND_SET_AUTO_SELF_CALIBRATION_STANDARD_PERIOD   0x244EU
#define SCD4X_COMMAND_GET_AUTO_SELF_CALIBRATION_STANDARD_PERIOD   0x234BU
#define SCD4X_CRC8_POLYNOMIAL   0x31
 crc8 definition
#define SCD4X_CRC8_INIT   0xFF

Functions

uint8_t scd4x_set_type (scd4x_handle_t *handle, scd4x_t type)
 set type
uint8_t scd4x_get_type (scd4x_handle_t *handle, scd4x_t *type)
 get type
uint8_t scd4x_start_periodic_measurement (scd4x_handle_t *handle)
 start periodic measurement
uint8_t scd4x_read (scd4x_handle_t *handle, uint16_t *co2_raw, uint16_t *co2_ppm, uint16_t *temperature_raw, float *temperature_s, uint16_t *humidity_raw, float *humidity_s)
 read data
uint8_t scd4x_stop_periodic_measurement (scd4x_handle_t *handle)
 stop periodic measurement
uint8_t scd4x_set_temperature_offset (scd4x_handle_t *handle, uint16_t offset)
 set temperature offset
uint8_t scd4x_get_temperature_offset (scd4x_handle_t *handle, uint16_t *offset)
 get temperature offset
uint8_t scd4x_temperature_offset_convert_to_register (scd4x_handle_t *handle, float degrees, uint16_t *reg)
 convert the temperature offset to the register raw data
uint8_t scd4x_temperature_offset_convert_to_data (scd4x_handle_t *handle, uint16_t reg, float *degrees)
 convert the register raw data to the temperature offset
uint8_t scd4x_set_sensor_altitude (scd4x_handle_t *handle, uint16_t altitude)
 set sensor altitude
uint8_t scd4x_get_sensor_altitude (scd4x_handle_t *handle, uint16_t *altitude)
 get sensor altitude
uint8_t scd4x_sensor_altitude_convert_to_register (scd4x_handle_t *handle, float m, uint16_t *reg)
 convert the sensor altitude to the register raw data
uint8_t scd4x_sensor_altitude_convert_to_data (scd4x_handle_t *handle, uint16_t reg, float *m)
 convert the register raw data to the sensor altitude
uint8_t scd4x_set_ambient_pressure (scd4x_handle_t *handle, uint16_t pressure)
 set ambient pressure
uint8_t scd4x_get_ambient_pressure (scd4x_handle_t *handle, uint16_t *pressure)
 get ambient pressure
uint8_t scd4x_ambient_pressure_convert_to_register (scd4x_handle_t *handle, float pa, uint16_t *reg)
 convert the ambient pressure to the register raw data
uint8_t scd4x_ambient_pressure_convert_to_data (scd4x_handle_t *handle, uint16_t reg, float *pa)
 convert the register raw data to the ambient pressure
uint8_t scd4x_perform_forced_recalibration (scd4x_handle_t *handle, uint16_t co2_raw, uint16_t *frc)
 perform forced recalibration
uint8_t scd4x_co2_convert_to_register (scd4x_handle_t *handle, float ppm, uint16_t *reg)
 convert the co2 to the register raw data
uint8_t scd4x_co2_convert_to_data (scd4x_handle_t *handle, uint16_t reg, float *ppm)
 convert the register raw data to the co2
uint8_t scd4x_set_automatic_self_calibration (scd4x_handle_t *handle, scd4x_bool_t enable)
 enable or disable automatic self calibration
uint8_t scd4x_get_automatic_self_calibration (scd4x_handle_t *handle, scd4x_bool_t *enable)
 get automatic self calibration status
uint8_t scd4x_start_low_power_periodic_measurement (scd4x_handle_t *handle)
 start low power periodic measurement
uint8_t scd4x_get_data_ready_status (scd4x_handle_t *handle, scd4x_bool_t *enable)
 get data ready status
uint8_t scd4x_persist_settings (scd4x_handle_t *handle)
 persist settings
uint8_t scd4x_get_serial_number (scd4x_handle_t *handle, uint16_t number[3])
 get serial number
uint8_t scd4x_perform_self_test (scd4x_handle_t *handle, scd4x_bool_t *malfunction_detected)
 perform self test
uint8_t scd4x_perform_factory_reset (scd4x_handle_t *handle)
 perform factory reset
uint8_t scd4x_reinit (scd4x_handle_t *handle)
 reinit
uint8_t scd4x_measure_single_shot (scd4x_handle_t *handle)
 measure single shot
uint8_t scd4x_measure_single_shot_rht_only (scd4x_handle_t *handle)
 measure single shot rht only
uint8_t scd4x_power_down (scd4x_handle_t *handle)
 power down
uint8_t scd4x_wake_up (scd4x_handle_t *handle)
 wake up
uint8_t scd4x_set_automatic_self_calibration_initial_period (scd4x_handle_t *handle, uint16_t hour)
 set automatic self calibration initial period
uint8_t scd4x_get_automatic_self_calibration_initial_period (scd4x_handle_t *handle, uint16_t *hour)
 get automatic self calibration initial period
uint8_t scd4x_set_automatic_self_calibration_standard_period (scd4x_handle_t *handle, uint16_t hour)
 set automatic self calibration standard period
uint8_t scd4x_get_automatic_self_calibration_standard_period (scd4x_handle_t *handle, uint16_t *hour)
 get automatic self calibration standard period
uint8_t scd4x_init (scd4x_handle_t *handle)
 initialize the chip
uint8_t scd4x_deinit (scd4x_handle_t *handle)
 close the chip
uint8_t scd4x_set_reg (scd4x_handle_t *handle, uint16_t reg, uint8_t *buf, uint16_t len)
 set the chip register
uint8_t scd4x_get_reg (scd4x_handle_t *handle, uint16_t reg, uint8_t *buf, uint16_t len, uint16_t delay_ms)
 get the chip register
uint8_t scd4x_info (scd4x_info_t *info)
 get chip information

Detailed Description

driver scd4x source file

Copyright (c) 2015 - present LibDriver All rights reserved

The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Version
1.0.0
Author
Shifeng Li
Date
2023-09-25

history

Date Version Author Description
2023/09/25 1.0 Shifeng Li first upload

Definition in file driver_scd4x.c.

Macro Definition Documentation

◆ CHIP_NAME

#define CHIP_NAME   "Sensirion SCD4X"

chip information definition

chip name

Definition at line 42 of file driver_scd4x.c.

◆ DRIVER_VERSION

#define DRIVER_VERSION   1000

driver version

Definition at line 49 of file driver_scd4x.c.

◆ MANUFACTURER_NAME

#define MANUFACTURER_NAME   "Sensirion"

manufacturer name

Definition at line 43 of file driver_scd4x.c.

◆ MAX_CURRENT

#define MAX_CURRENT   205.0f

chip max current

Definition at line 46 of file driver_scd4x.c.

◆ SCD4X_ADDRESS

#define SCD4X_ADDRESS   (0x62 << 1)

chip address definition

chip iic address

Definition at line 54 of file driver_scd4x.c.

◆ SCD4X_COMMAND_GET_AMBIENT_PRESSURE

#define SCD4X_COMMAND_GET_AMBIENT_PRESSURE   0xE000U

get ambient pressure command

Definition at line 67 of file driver_scd4x.c.

◆ SCD4X_COMMAND_GET_AUTO_SELF_CALIBRATION

#define SCD4X_COMMAND_GET_AUTO_SELF_CALIBRATION   0x2313U

get automatic self calibration enabled command

Definition at line 70 of file driver_scd4x.c.

◆ SCD4X_COMMAND_GET_AUTO_SELF_CALIBRATION_INIT_PERIOD

#define SCD4X_COMMAND_GET_AUTO_SELF_CALIBRATION_INIT_PERIOD   0x2340U

get automatic self calibration initial period command

Definition at line 83 of file driver_scd4x.c.

◆ SCD4X_COMMAND_GET_AUTO_SELF_CALIBRATION_STANDARD_PERIOD

#define SCD4X_COMMAND_GET_AUTO_SELF_CALIBRATION_STANDARD_PERIOD   0x234BU

get automatic self calibration standard period command

Definition at line 85 of file driver_scd4x.c.

◆ SCD4X_COMMAND_GET_DATA_READY_STATUS

#define SCD4X_COMMAND_GET_DATA_READY_STATUS   0xE4B8U

get data ready status command

Definition at line 72 of file driver_scd4x.c.

◆ SCD4X_COMMAND_GET_SENSOR_ALTITUDE

#define SCD4X_COMMAND_GET_SENSOR_ALTITUDE   0x2322U

get sensor altitude command

Definition at line 65 of file driver_scd4x.c.

◆ SCD4X_COMMAND_GET_SERIAL_NUMBER

#define SCD4X_COMMAND_GET_SERIAL_NUMBER   0x3682U

get serial number command

Definition at line 74 of file driver_scd4x.c.

◆ SCD4X_COMMAND_GET_TEMPERATURE_OFFSET

#define SCD4X_COMMAND_GET_TEMPERATURE_OFFSET   0x2318U

get temperature offset command

Definition at line 63 of file driver_scd4x.c.

◆ SCD4X_COMMAND_MEASURE_SINGLE_SHOT

#define SCD4X_COMMAND_MEASURE_SINGLE_SHOT   0x219DU

measure single shot command

Definition at line 78 of file driver_scd4x.c.

◆ SCD4X_COMMAND_MEASURE_SINGLE_SHOT_RHT_ONLY

#define SCD4X_COMMAND_MEASURE_SINGLE_SHOT_RHT_ONLY   0x2196U

measure single shot rht only command

Definition at line 79 of file driver_scd4x.c.

◆ SCD4X_COMMAND_PERFORM_FACTORY_RESET

#define SCD4X_COMMAND_PERFORM_FACTORY_RESET   0x3632U

perform factory reset command

Definition at line 76 of file driver_scd4x.c.

◆ SCD4X_COMMAND_PERFORM_FORCED_RECALIBRATION

#define SCD4X_COMMAND_PERFORM_FORCED_RECALIBRATION   0x362FU

perform forced recalibration command

Definition at line 68 of file driver_scd4x.c.

◆ SCD4X_COMMAND_PERFORM_SELF_TEST

#define SCD4X_COMMAND_PERFORM_SELF_TEST   0x3639U

perform self test command

Definition at line 75 of file driver_scd4x.c.

◆ SCD4X_COMMAND_PERSIST_SETTINGS

#define SCD4X_COMMAND_PERSIST_SETTINGS   0x3615U

persist settings command

Definition at line 73 of file driver_scd4x.c.

◆ SCD4X_COMMAND_POWER_DOWN

#define SCD4X_COMMAND_POWER_DOWN   0x36E0U

power down command

Definition at line 80 of file driver_scd4x.c.

◆ SCD4X_COMMAND_READ

#define SCD4X_COMMAND_READ   0xEC05U

read measurement command

Definition at line 60 of file driver_scd4x.c.

◆ SCD4X_COMMAND_REINIT

#define SCD4X_COMMAND_REINIT   0x3646U

reinit command

Definition at line 77 of file driver_scd4x.c.

◆ SCD4X_COMMAND_SET_AMBIENT_PRESSURE

#define SCD4X_COMMAND_SET_AMBIENT_PRESSURE   0xE000U

set ambient pressure command

Definition at line 66 of file driver_scd4x.c.

◆ SCD4X_COMMAND_SET_AUTO_SELF_CALIBRATION

#define SCD4X_COMMAND_SET_AUTO_SELF_CALIBRATION   0x2416U

set automatic self calibration enabled command

Definition at line 69 of file driver_scd4x.c.

◆ SCD4X_COMMAND_SET_AUTO_SELF_CALIBRATION_INIT_PERIOD

#define SCD4X_COMMAND_SET_AUTO_SELF_CALIBRATION_INIT_PERIOD   0x2445U

set automatic self calibration initial period command

Definition at line 82 of file driver_scd4x.c.

◆ SCD4X_COMMAND_SET_AUTO_SELF_CALIBRATION_STANDARD_PERIOD

#define SCD4X_COMMAND_SET_AUTO_SELF_CALIBRATION_STANDARD_PERIOD   0x244EU

set automatic self calibration standard period command

Definition at line 84 of file driver_scd4x.c.

◆ SCD4X_COMMAND_SET_SENSOR_ALTITUDE

#define SCD4X_COMMAND_SET_SENSOR_ALTITUDE   0x2427U

set sensor altitude command

Definition at line 64 of file driver_scd4x.c.

◆ SCD4X_COMMAND_SET_TEMPERATURE_OFFSET

#define SCD4X_COMMAND_SET_TEMPERATURE_OFFSET   0x241DU

set temperature offset command

Definition at line 62 of file driver_scd4x.c.

◆ SCD4X_COMMAND_START_LOW_POWER_PERIODIC

#define SCD4X_COMMAND_START_LOW_POWER_PERIODIC   0x21ACU

start low power periodic measurement command

Definition at line 71 of file driver_scd4x.c.

◆ SCD4X_COMMAND_START_PERIODIC

#define SCD4X_COMMAND_START_PERIODIC   0x21B1U

chip command definition

start periodic measurement command

Definition at line 59 of file driver_scd4x.c.

◆ SCD4X_COMMAND_STOP_PERIODIC

#define SCD4X_COMMAND_STOP_PERIODIC   0x3F86U

stop periodic measurement command

Definition at line 61 of file driver_scd4x.c.

◆ SCD4X_COMMAND_WAKE_UP

#define SCD4X_COMMAND_WAKE_UP   0x36F6U

wake up command

Definition at line 81 of file driver_scd4x.c.

◆ SCD4X_CRC8_INIT

#define SCD4X_CRC8_INIT   0xFF

Definition at line 91 of file driver_scd4x.c.

◆ SCD4X_CRC8_POLYNOMIAL

#define SCD4X_CRC8_POLYNOMIAL   0x31

crc8 definition

Definition at line 90 of file driver_scd4x.c.

◆ SUPPLY_VOLTAGE_MAX

#define SUPPLY_VOLTAGE_MAX   5.50f

chip max supply voltage

Definition at line 45 of file driver_scd4x.c.

◆ SUPPLY_VOLTAGE_MIN

#define SUPPLY_VOLTAGE_MIN   2.40f

chip min supply voltage

Definition at line 44 of file driver_scd4x.c.

◆ TEMPERATURE_MAX

#define TEMPERATURE_MAX   60.0f

chip max operating temperature

Definition at line 48 of file driver_scd4x.c.

◆ TEMPERATURE_MIN

#define TEMPERATURE_MIN   -10.0f

chip min operating temperature

Definition at line 47 of file driver_scd4x.c.