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] i2cspmThe I2CSPM instance to use.
- Returns
- Return values
-
SL_STATUS_OKSuccess SL_STATUS_INITIALIZATIONInitialization was unsuccessful
◆ sl_ccs811_deinit()
| sl_status_t sl_ccs811_deinit | ( | sl_i2cspm_t * |
i2cspm
|
) |
De-initialize the chip.
- Parameters
-
[in] i2cspmThe I2CSPM instance to use.
- Returns
- Return values
-
SL_STATUS_OKSuccess
◆ 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] i2cspmThe I2CSPM instance to use. [out] hwIDThe Hardware ID of the chip (should be 0x81)
- Returns
- Return values
-
SL_STATUS_OKSuccess SL_STATUS_TRANSMITI2C 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] i2cspmThe I2CSPM instance to use. [in] measModeThe desired measurement mode
- Returns
- Return values
-
SL_STATUS_OKSuccess SL_STATUS_TRANSMITI2C 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] i2cspmThe I2CSPM instance to use. [in] firmwareA buffer containing the contents of the firmware update [in] lengthThe length of the firmware update array
- Returns
- Return values
-
SL_STATUS_OKFirmware upgrade successful SL_STATUS_FAILFirmware 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] i2cspmThe i2cspm instance to use [out] fw_versionThe 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_OKSuccess SL_STATUS_TRANSMITI2C 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] i2cspmThe I2CSPM instance to use. [out] statusThe content of the CCS811 Status Register
- Returns
- Return values
-
SL_STATUS_OKSuccess SL_STATUS_TRANSMITI2C 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] i2cspmThe I2CSPM instance to use. [in] idThe address of the Mailbox register [in] lengthThe number of bytes to read [out] dataThe data read from the sensor
- Returns
- Return values
-
SL_STATUS_OKSuccess SL_STATUS_TRANSMITI2C 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] i2cspmThe I2CSPM instance to use
- Returns
- Return values
-
SL_STATUS_OKSuccess SL_STATUS_TRANSMITI2C transmission failure SL_STATUS_NOT_AVAILABLEApplication firmware is not present in the CCS811 device SL_STATUS_INVALID_STATEChip 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] i2cspmThe I2CSPM instance to use
- Returns
- Return values
-
SL_STATUS_OKSuccess SL_STATUS_TRANSMITI2C 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] i2cspmThe 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] i2cspmThe I2CSPM instance to use [out] eco2The equivalent CO2 level (in ppm) read from the sensor [out] tvocThe TVOC level (in ppb) read from the sensor
- Returns
- Return values
-
SL_STATUS_OKSuccess SL_STATUS_TRANSMITI2C 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] i2cspmThe I2CSPM instance to use [out] currentThe value of current through the sensor [out] rawDataThe raw ADC reading of the voltage across the sensor with the selected current
- Returns
- Return values
-
SL_STATUS_OKSuccess SL_STATUS_TRANSMITI2C 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] i2cspmThe I2CSPM instance to use. [in] tempDataThe environmental temperature in milliCelsius [in] rhDataThe relative humidity in millipercent
- Returns
- Return values
-
SL_STATUS_OKSuccess SL_STATUS_TRANSMITI2C transmission error