CCS811 - Gas Sensor
Description
Driver for the Cambridge CMOS Sensors CCS811 gas and indoor air quality sensor.
CCS811 usage example code
Basic example for initializing measuring equivalent Co2 and TVOC level.
#include "sl_i2cspm_instances.h" #include "sl_ccs811.h" int main( void ) { ... // Initialize sensor and set measure mode sl_ccs811_init(sl_i2cspm_sensor_gas); sl_ccs811_set_measure_mode(sl_i2cspm_sensor_gas, CCS811_MEASURE_MODE_DRIVE_MODE_1SEC); uint16_t eco2; uint16_t tvoc; while (true) { if ( sl_ccs811_is_data_available(sl_i2cspm_sensor_gas) ) { sl_ccs811_get_measurement(sl_i2cspm_sensor_gas, &eco2, &tvoc); } ... } }
Modules |
|
CCS881 - Gas Sensor Details | |
CCS881 register interface.
|
|
Functions |
|
sl_status_t | sl_ccs811_init (sl_i2cspm_t *i2cspm) |
Initialize the chip.
|
|
sl_status_t | sl_ccs811_deinit (sl_i2cspm_t *i2cspm) |
De-initialize the chip.
|
|
sl_status_t | sl_ccs811_get_hardware_id (sl_i2cspm_t *i2cspm, uint8_t *hwID) |
Reads Hardware ID from the CCS811 sensor.
|
|
sl_status_t | sl_ccs811_set_measure_mode (sl_i2cspm_t *i2cspm, uint8_t measMode) |
Set the measurement mode of the CCS811 sensor.
|
|
sl_status_t | sl_ccs811_update_firmware (sl_i2cspm_t *i2cspm, const uint8_t *firmware, uint32_t length) |
Perform a firmware update of the CCS811 sensor.
|
|
sl_status_t | sl_ccs811_read_firmware_version (sl_i2cspm_t *i2cspm, uint16_t *fw_version) |
Read out current firmware of the CCS811 sensor.
|
|
sl_status_t | sl_ccs811_get_status (sl_i2cspm_t *i2cspm, uint8_t *status) |
Read the status of the CCS811 sensor.
|
|
sl_status_t | sl_ccs811_read_mailbox (sl_i2cspm_t *i2cspm, uint8_t id, uint8_t length, uint8_t *data) |
Read data from a specific Mailbox address.
|
|
sl_status_t | sl_ccs811_start_application (sl_i2cspm_t *i2cspm) |
Switch the CCS811 chip from boot to application mode.
|
|
sl_status_t | sl_ccs811_software_reset (sl_i2cspm_t *i2cspm) |
Perform software reset on the CCS811.
|
|
bool | sl_ccs811_is_data_available (sl_i2cspm_t *i2cspm) |
Check whether new measurement data is available.
|
|
sl_status_t | sl_ccs811_get_measurement (sl_i2cspm_t *i2cspm, uint16_t *eco2, uint16_t *tvoc) |
Read measurement data (eCO2 and TVOC) from the CCS811 sensor.
|
|
sl_status_t | sl_ccs811_get_raw_data (sl_i2cspm_t *i2cspm, uint16_t *current, uint16_t *rawData) |
Get the latest readings from the sense resistor of the CCS811 sensor.
|
|
sl_status_t | sl_ccs811_set_env_data (sl_i2cspm_t *i2cspm, int32_t tempData, uint32_t rhData) |
Write temperature and humidity values to the environmental data regs.
|
|
Function Documentation
◆ sl_ccs811_init()
sl_status_t sl_ccs811_init | ( | sl_i2cspm_t * |
i2cspm
|
) |
Initialize the chip.
- Parameters
-
[in] i2cspm
The I2CSPM instance to use.
- Returns
- Return values
-
SL_STATUS_OK
Success SL_STATUS_INITIALIZATION
Initialization was unsuccessful
◆ sl_ccs811_deinit()
sl_status_t sl_ccs811_deinit | ( | sl_i2cspm_t * |
i2cspm
|
) |
De-initialize the chip.
- Parameters
-
[in] i2cspm
The I2CSPM instance to use.
- Returns
- Return values
-
SL_STATUS_OK
Success
◆ sl_ccs811_get_hardware_id()
sl_status_t sl_ccs811_get_hardware_id | ( | sl_i2cspm_t * |
i2cspm,
|
uint8_t * |
hwID
|
||
) |
Reads Hardware ID from the CCS811 sensor.
- Parameters
-
[in] i2cspm
The I2CSPM instance to use. [out] hwID
The Hardware ID of the chip (should be 0x81)
- Returns
- Return values
-
SL_STATUS_OK
Success SL_STATUS_TRANSMIT
I2C transmission error
◆ sl_ccs811_set_measure_mode()
sl_status_t sl_ccs811_set_measure_mode | ( | sl_i2cspm_t * |
i2cspm,
|
uint8_t |
measMode
|
||
) |
Set the measurement mode of the CCS811 sensor.
This function must be called before reading measurements from the sensor.
- Parameters
-
[in] i2cspm
The I2CSPM instance to use. [in] measMode
The desired measurement mode
- Returns
- Return values
-
SL_STATUS_OK
Success SL_STATUS_TRANSMIT
I2C transmission error
◆ sl_ccs811_update_firmware()
sl_status_t sl_ccs811_update_firmware | ( | sl_i2cspm_t * |
i2cspm,
|
const uint8_t * |
firmware,
|
||
uint32_t |
length
|
||
) |
Perform a firmware update of the CCS811 sensor.
This function overwrites the existing firmware, irrespective of the version number.
- Parameters
-
[in] i2cspm
The I2CSPM instance to use. [in] firmware
A buffer containing the contents of the firmware update [in] length
The length of the firmware update array
- Returns
- Return values
-
SL_STATUS_OK
Firmware upgrade successful SL_STATUS_FAIL
Firmware upgrade failed
◆ sl_ccs811_read_firmware_version()
sl_status_t sl_ccs811_read_firmware_version | ( | sl_i2cspm_t * |
i2cspm,
|
uint16_t * |
fw_version
|
||
) |
Read out current firmware of the CCS811 sensor.
- Parameters
-
[in] i2cspm
The i2cspm instance to use [out] fw_version
The current application firmware. The top 4 bits contain the major firmware version, the next 4 bits contain the minor and the last 8 bits contain the patch version.
- Return values
-
SL_STATUS_OK
Success SL_STATUS_TRANSMIT
I2C transmission error
◆ sl_ccs811_get_status()
sl_status_t sl_ccs811_get_status | ( | sl_i2cspm_t * |
i2cspm,
|
uint8_t * |
status
|
||
) |
Read the status of the CCS811 sensor.
- Parameters
-
[in] i2cspm
The I2CSPM instance to use. [out] status
The content of the CCS811 Status Register
- Returns
- Return values
-
SL_STATUS_OK
Success SL_STATUS_TRANSMIT
I2C transmission error
◆ sl_ccs811_read_mailbox()
sl_status_t sl_ccs811_read_mailbox | ( | sl_i2cspm_t * |
i2cspm,
|
uint8_t |
id,
|
||
uint8_t |
length,
|
||
uint8_t * |
data
|
||
) |
Read data from a specific Mailbox address.
- Parameters
-
[in] i2cspm
The I2CSPM instance to use. [in] id
The address of the Mailbox register [in] length
The number of bytes to read [out] data
The data read from the sensor
- Returns
- Return values
-
SL_STATUS_OK
Success SL_STATUS_TRANSMIT
I2C transmission error
◆ sl_ccs811_start_application()
sl_status_t sl_ccs811_start_application | ( | sl_i2cspm_t * |
i2cspm
|
) |
Switch the CCS811 chip from boot to application mode.
- Parameters
-
[in] i2cspm
The I2CSPM instance to use
- Returns
- Return values
-
SL_STATUS_OK
Success SL_STATUS_TRANSMIT
I2C transmission failure SL_STATUS_NOT_AVAILABLE
Application firmware is not present in the CCS811 device SL_STATUS_INVALID_STATE
Chip firmware did not switch to application mode
◆ sl_ccs811_software_reset()
sl_status_t sl_ccs811_software_reset | ( | sl_i2cspm_t * |
i2cspm
|
) |
Perform software reset on the CCS811.
- Parameters
-
[in] i2cspm
The I2CSPM instance to use
- Returns
- Return values
-
SL_STATUS_OK
Success SL_STATUS_TRANSMIT
I2C transmission error
◆ sl_ccs811_is_data_available()
bool sl_ccs811_is_data_available | ( | sl_i2cspm_t * |
i2cspm
|
) |
Check whether new measurement data is available.
- Parameters
-
[in] i2cspm
The I2CSPM instance to use
- Returns
- True if new data available, otherwise false
◆ sl_ccs811_get_measurement()
sl_status_t sl_ccs811_get_measurement | ( | sl_i2cspm_t * |
i2cspm,
|
uint16_t * |
eco2,
|
||
uint16_t * |
tvoc
|
||
) |
Read measurement data (eCO2 and TVOC) from the CCS811 sensor.
- Parameters
-
[in] i2cspm
The I2CSPM instance to use [out] eco2
The equivalent CO2 level (in ppm) read from the sensor [out] tvoc
The TVOC level (in ppb) read from the sensor
- Returns
- Return values
-
SL_STATUS_OK
Success SL_STATUS_TRANSMIT
I2C transmission error
◆ sl_ccs811_get_raw_data()
sl_status_t sl_ccs811_get_raw_data | ( | sl_i2cspm_t * |
i2cspm,
|
uint16_t * |
current,
|
||
uint16_t * |
rawData
|
||
) |
Get the latest readings from the sense resistor of the CCS811 sensor.
- Parameters
-
[in] i2cspm
The I2CSPM instance to use [out] current
The value of current through the sensor [out] rawData
The raw ADC reading of the voltage across the sensor with the selected current
- Returns
- Return values
-
SL_STATUS_OK
Success SL_STATUS_TRANSMIT
I2C transmission error
◆ sl_ccs811_set_env_data()
sl_status_t sl_ccs811_set_env_data | ( | sl_i2cspm_t * |
i2cspm,
|
int32_t |
tempData,
|
||
uint32_t |
rhData
|
||
) |
Write temperature and humidity values to the environmental data regs.
- Parameters
-
[in] i2cspm
The I2CSPM instance to use. [in] tempData
The environmental temperature in milliCelsius [in] rhData
The relative humidity in millipercent
- Returns
- Return values
-
SL_STATUS_OK
Success SL_STATUS_TRANSMIT
I2C transmission error