CCS811 - Gas Sensor#
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#
Functions#
Initialize the chip.
De-initialize the chip.
Reads Hardware ID from the CCS811 sensor.
Set the measurement mode of the CCS811 sensor.
Perform a firmware update of the CCS811 sensor.
Read out current firmware of the CCS811 sensor.
Read the status of the CCS811 sensor.
Read data from a specific Mailbox address.
Switch the CCS811 chip from boot to application mode.
Perform software reset on the CCS811.
Check whether new measurement data is available.
Read measurement data (eCO2 and TVOC) from the CCS811 sensor.
Get the latest readings from the sense resistor of the CCS811 sensor.
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.
[in] | i2cspm | The I2CSPM instance to use. |
Returns
Return values
SL_STATUS_OK: Success
SL_STATUS_INITIALIZATION: Initialization was unsuccessful
137
of file hardware/driver/ccs811/inc/sl_ccs811.h
sl_ccs811_deinit#
sl_status_t sl_ccs811_deinit (sl_i2cspm_t * i2cspm)
De-initialize the chip.
[in] | i2cspm | The I2CSPM instance to use. |
Returns
Return values
SL_STATUS_OK: Success
149
of file hardware/driver/ccs811/inc/sl_ccs811.h
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.
[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
165
of file hardware/driver/ccs811/inc/sl_ccs811.h
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.
[in] | i2cspm | The I2CSPM instance to use. |
[in] | measMode | The desired measurement mode |
This function must be called before reading measurements from the sensor.
Returns
Return values
SL_STATUS_OK: Success
SL_STATUS_TRANSMIT: I2C transmission error
184
of file hardware/driver/ccs811/inc/sl_ccs811.h
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.
[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 |
This function overwrites the existing firmware, irrespective of the version number.
Returns
Return values
SL_STATUS_OK: Firmware upgrade successful
SL_STATUS_FAIL: Firmware upgrade failed
207
of file hardware/driver/ccs811/inc/sl_ccs811.h
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.
[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. |
223
of file hardware/driver/ccs811/inc/sl_ccs811.h
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.
[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
239
of file hardware/driver/ccs811/inc/sl_ccs811.h
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.
[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
261
of file hardware/driver/ccs811/inc/sl_ccs811.h
sl_ccs811_start_application#
sl_status_t sl_ccs811_start_application (sl_i2cspm_t * i2cspm)
Switch the CCS811 chip from boot to application mode.
[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
276
of file hardware/driver/ccs811/inc/sl_ccs811.h
sl_ccs811_software_reset#
sl_status_t sl_ccs811_software_reset (sl_i2cspm_t * i2cspm)
Perform software reset on the CCS811.
[in] | i2cspm | The I2CSPM instance to use |
Returns
Return values
SL_STATUS_OK: Success
SL_STATUS_TRANSMIT: I2C transmission error
289
of file hardware/driver/ccs811/inc/sl_ccs811.h
sl_ccs811_is_data_available#
bool sl_ccs811_is_data_available (sl_i2cspm_t * i2cspm)
Check whether new measurement data is available.
[in] | i2cspm | The I2CSPM instance to use |
Returns
True if new data available, otherwise false
301
of file hardware/driver/ccs811/inc/sl_ccs811.h
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.
[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
320
of file hardware/driver/ccs811/inc/sl_ccs811.h
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.
[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
340
of file hardware/driver/ccs811/inc/sl_ccs811.h
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.
[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
359
of file hardware/driver/ccs811/inc/sl_ccs811.h