CCS811 - Indoor Air Quality SensorBSP > Thunderboard Sense BSP
Detailed Description
Driver for the Cambridge CMOS Sensors CCS811 gas and indoor air quality sensor.
| Functions | |
| uint32_t | CCS811_deInit (void) | 
| De-initializes the chip. | |
| void | CCS811_dumpRegisters (void) | 
| Dumps the registers of the CSS811. | |
| uint32_t | CCS811_getHardwareID (uint8_t *hardwareID) | 
| Reads Hardware ID from the CSS811 sensor. | |
| uint32_t | CCS811_getMeasurement (uint16_t *eco2, uint16_t *tvoc) | 
| Reads measurement data (eCO2 and TVOC) from the CSS811 sensor. | |
| uint32_t | CCS811_getRawData (uint16_t *current, uint16_t *rawData) | 
| Gets the latest readings from the sense resistor of the CSS811 sensor. | |
| uint32_t | CCS811_getStatus (uint8_t *status) | 
| Reads the status of the CSS811 sensor. | |
| uint32_t | CCS811_init (void) | 
| Initializes the chip and performs firmware upgrade if required. | |
| bool | CCS811_isDataAvailable (void) | 
| Checks if new measurement data available. | |
| uint32_t | CCS811_readMailbox (uint8_t id, uint8_t length, uint8_t *data) | 
| Reads data from a specific Mailbox address. | |
| uint32_t | CCS811_setEnvData (int32_t tempData, uint32_t rhData) | 
| Writes temperature and humidity values to the environmental data regs. | |
| uint32_t | CCS811_setMeasureMode (uint8_t measMode) | 
| Sets the measurement mode of the CSS811 sensor. | |
| uint32_t | CCS811_softwareReset (void) | 
| Performs software reset on the CCS811. | |
| uint32_t | CCS811_startApplication (void) | 
| Switches the CSS811 chip from boot to application mode. | |
| Error Codes | |
| #define | CCS811_OK 0x0000 | 
| #define | CCS811_ERROR_APPLICATION_NOT_PRESENT 0x0001 | 
| #define | CCS811_ERROR_NOT_IN_APPLICATION_MODE 0x0002 | 
| #define | CCS811_ERROR_DRIVER_NOT_INITIALIZED 0x0003 | 
| #define | CCS811_ERROR_I2C_TRANSACTION_FAILED 0x0004 | 
| #define | CCS811_ERROR_INIT_FAILED 0x0005 | 
| #define | CCS811_ERROR_FIRMWARE_UPDATE_FAILED 0x0006 | 
| Register Addresses | |
| #define | CCS811_ADDR_STATUS 0x00 | 
| #define | CCS811_ADDR_MEASURE_MODE 0x01 | 
| #define | CCS811_ADDR_ALG_RESULT_DATA 0x02 | 
| #define | CCS811_ADDR_RAW_DATA 0x03 | 
| #define | CCS811_ADDR_ENV_DATA 0x05 | 
| #define | CCS811_ADDR_NTC 0x06 | 
| #define | CCS811_ADDR_THRESHOLDS 0x10 | 
| #define | CCS811_ADDR_HW_ID 0x20 | 
| #define | CCS811_ADDR_HW_VERSION 0x21 | 
| #define | CCS811_ADDR_FW_BOOT_VERSION 0x23 | 
| #define | CCS811_ADDR_FW_APP_VERSION 0x24 | 
| #define | CCS811_ADDR_ERR_ID 0xE0 | 
| #define | CCS811_ADDR_FW_ERASE 0xF1 | 
| #define | CCS811_ADDR_FW_PROGRAM 0xF2 | 
| #define | CCS811_ADDR_FW_VERIFY 0xF3 | 
| #define | CCS811_ADDR_APP_START 0xF4 | 
| #define | CCS811_ADDR_SW_RESET 0xFF | 
| Measure mode value definitions | |
| #define | CCS811_MEASURE_MODE_DRIVE_MODE_SHIFT 4 | 
| #define | CCS811_MEASURE_MODE_DRIVE_MODE_IDLE 0x00 | 
| #define | CCS811_MEASURE_MODE_DRIVE_MODE_1SEC 0x10 | 
| #define | CCS811_MEASURE_MODE_DRIVE_MODE_10SEC 0x20 | 
| #define | CCS811_MEASURE_MODE_DRIVE_MODE_60SEC 0x30 | 
| #define | CCS811_MEASURE_MODE_DRIVE_MODE_RAW 0x40 | 
| #define | CCS811_MEASURE_MODE_INTERRUPT 0x08 | 
| #define | CCS811_MEASURE_MODE_THRESH 0x04 | 
Macro Definition Documentation
| #define CCS811_ADDR_ALG_RESULT_DATA 0x02 | 
Algorithm result
        Definition at line
        
         53
        
        of file
        
         ccs811.h
        
        .
       
Referenced by CCS811_dumpRegisters() , and CCS811_getMeasurement() .
| #define CCS811_ADDR_APP_START 0xF4 | 
Application start
        Definition at line
        
         66
        
        of file
        
         ccs811.h
        
        .
       
| #define CCS811_ADDR_ENV_DATA 0x05 | 
Temperature and Humidity data can be written to enable compensation
        Definition at line
        
         55
        
        of file
        
         ccs811.h
        
        .
       
Referenced by CCS811_dumpRegisters() , and CCS811_setEnvData() .
| #define CCS811_ADDR_ERR_ID 0xE0 | 
| #define CCS811_ADDR_FW_APP_VERSION 0x24 | 
Firmware Application Version
        Definition at line
        
         61
        
        of file
        
         ccs811.h
        
        .
       
Referenced by CCS811_dumpRegisters() .
| #define CCS811_ADDR_FW_BOOT_VERSION 0x23 | 
Firmware Boot Version
        Definition at line
        
         60
        
        of file
        
         ccs811.h
        
        .
       
Referenced by CCS811_dumpRegisters() .
| #define CCS811_ADDR_FW_ERASE 0xF1 | 
Firmware erase
        Definition at line
        
         63
        
        of file
        
         ccs811.h
        
        .
       
| #define CCS811_ADDR_FW_PROGRAM 0xF2 | 
Firmware programming
        Definition at line
        
         64
        
        of file
        
         ccs811.h
        
        .
       
| #define CCS811_ADDR_FW_VERIFY 0xF3 | 
Firmware verification
        Definition at line
        
         65
        
        of file
        
         ccs811.h
        
        .
       
| #define CCS811_ADDR_HW_ID 0x20 | 
Hardware ID
        Definition at line
        
         58
        
        of file
        
         ccs811.h
        
        .
       
Referenced by CCS811_dumpRegisters() , and CCS811_getHardwareID() .
| #define CCS811_ADDR_HW_VERSION 0x21 | 
| #define CCS811_ADDR_MEASURE_MODE 0x01 | 
Measurement mode and conditions register
        Definition at line
        
         52
        
        of file
        
         ccs811.h
        
        .
       
Referenced by CCS811_dumpRegisters() , and CCS811_setMeasureMode() .
| #define CCS811_ADDR_NTC 0x06 | 
Provides the voltage across the reference resistor and the voltage across the NTC resistor
        Definition at line
        
         56
        
        of file
        
         ccs811.h
        
        .
       
Referenced by CCS811_dumpRegisters() .
| #define CCS811_ADDR_RAW_DATA 0x03 | 
Raw ADC data values for resistance and current source used
        Definition at line
        
         54
        
        of file
        
         ccs811.h
        
        .
       
Referenced by CCS811_dumpRegisters() , and CCS811_getRawData() .
| #define CCS811_ADDR_STATUS 0x00 | 
Status register
        Definition at line
        
         51
        
        of file
        
         ccs811.h
        
        .
       
Referenced by CCS811_dumpRegisters() , CCS811_getStatus() , and CCS811_startApplication() .
| #define CCS811_ADDR_SW_RESET 0xFF | 
| #define CCS811_ADDR_THRESHOLDS 0x10 | 
Thresholds for operation when interrupts are only generated when eCO2 ppm crosses a threshold
        Definition at line
        
         57
        
        of file
        
         ccs811.h
        
        .
       
Referenced by CCS811_dumpRegisters() .
| #define CCS811_ERROR_APPLICATION_NOT_PRESENT 0x0001 | 
Application firmware is not present
        Definition at line
        
         39
        
        of file
        
         ccs811.h
        
        .
       
Referenced by CCS811_startApplication() .
| #define CCS811_ERROR_DRIVER_NOT_INITIALIZED 0x0003 | 
The driver is not initialized
        Definition at line
        
         41
        
        of file
        
         ccs811.h
        
        .
       
| #define CCS811_ERROR_FIRMWARE_UPDATE_FAILED 0x0006 | 
The firmware update was unsuccessful
        Definition at line
        
         44
        
        of file
        
         ccs811.h
        
        .
       
| #define CCS811_ERROR_I2C_TRANSACTION_FAILED 0x0004 | 
I2C transaction failed
        Definition at line
        
         42
        
        of file
        
         ccs811.h
        
        .
       
Referenced by CCS811_getMeasurement() , CCS811_getRawData() , CCS811_readMailbox() , CCS811_setEnvData() , CCS811_setMeasureMode() , and CCS811_softwareReset() .
| #define CCS811_ERROR_INIT_FAILED 0x0005 | 
| #define CCS811_ERROR_NOT_IN_APPLICATION_MODE 0x0002 | 
The part is not in application mode
        Definition at line
        
         40
        
        of file
        
         ccs811.h
        
        .
       
Referenced by CCS811_startApplication() .
| #define CCS811_MEASURE_MODE_DRIVE_MODE_10SEC 0x20 | 
IAQ Mode 2, a measurement is performed every 10 seconds
        Definition at line
        
         77
        
        of file
        
         ccs811.h
        
        .
       
| #define CCS811_MEASURE_MODE_DRIVE_MODE_1SEC 0x10 | 
IAQ Mode 1, a measurement is performed every second
        Definition at line
        
         76
        
        of file
        
         ccs811.h
        
        .
       
| #define CCS811_MEASURE_MODE_DRIVE_MODE_60SEC 0x30 | 
IAQ Mode 3, a measurement is performed every 60 seconds
        Definition at line
        
         78
        
        of file
        
         ccs811.h
        
        .
       
| #define CCS811_MEASURE_MODE_DRIVE_MODE_IDLE 0x00 | 
Idle mode, measurements are disabled
        Definition at line
        
         75
        
        of file
        
         ccs811.h
        
        .
       
| #define CCS811_MEASURE_MODE_DRIVE_MODE_RAW 0x40 | 
IAQ Mode 4, Raw Data Mode, a measurement is performed every 250ms for external algorithms
        Definition at line
        
         79
        
        of file
        
         ccs811.h
        
        .
       
| #define CCS811_MEASURE_MODE_DRIVE_MODE_SHIFT 4 | 
DRIVE_MODE field bit shift value
        Definition at line
        
         74
        
        of file
        
         ccs811.h
        
        .
       
| #define CCS811_MEASURE_MODE_INTERRUPT 0x08 | 
Interrupt generation enable
        Definition at line
        
         80
        
        of file
        
         ccs811.h
        
        .
       
| #define CCS811_MEASURE_MODE_THRESH 0x04 | 
Enable interrupt when eCO2 level exceeds threshold
        Definition at line
        
         81
        
        of file
        
         ccs811.h
        
        .
       
| #define CCS811_OK 0x0000 | 
No errors
        Definition at line
        
         38
        
        of file
        
         ccs811.h
        
        .
       
Referenced by CCS811_deInit() , CCS811_getMeasurement() , CCS811_getRawData() , CCS811_init() , CCS811_isDataAvailable() , CCS811_readMailbox() , CCS811_setEnvData() , CCS811_setMeasureMode() , and CCS811_softwareReset() .
Function Documentation
| uint32_t CCS811_deInit | ( | void | 
            | ) | 
De-initializes the chip.
- Returns
- Returns zero on OK, non-zero otherwise
        Definition at line
        
         98
        
        of file
        
         ccs811.c
        
        .
       
References BOARD_gasSensorEnable() , BOARD_gasSensorWake() , and CCS811_OK .
| void CCS811_dumpRegisters | ( | void | 
            | ) | 
Dumps the registers of the CSS811.
- Returns
- None
        Definition at line
        
         177
        
        of file
        
         ccs811.c
        
        .
       
References CCS811_ADDR_ALG_RESULT_DATA , CCS811_ADDR_ENV_DATA , CCS811_ADDR_ERR_ID , CCS811_ADDR_FW_APP_VERSION , CCS811_ADDR_FW_BOOT_VERSION , CCS811_ADDR_HW_ID , CCS811_ADDR_HW_VERSION , CCS811_ADDR_MEASURE_MODE , CCS811_ADDR_NTC , CCS811_ADDR_RAW_DATA , CCS811_ADDR_STATUS , CCS811_ADDR_THRESHOLDS , and CCS811_readMailbox() .
| uint32_t CCS811_getHardwareID | ( | uint8_t * | 
            hardwareID
            | ) | 
Reads Hardware ID from the CSS811 sensor.
- Parameters
- 
         [out] hardwareIDThe Hardware ID of the chip (should be 0x81) 
- Returns
- Returns zero on OK, non-zero otherwise
        Definition at line
        
         117
        
        of file
        
         ccs811.c
        
        .
       
References CCS811_ADDR_HW_ID , and CCS811_readMailbox() .
Referenced by CCS811_init() .
| uint32_t CCS811_getMeasurement | ( | uint16_t * | 
            eco2,
            | 
| uint16_t * | 
            tvoc
            | ||
| ) | 
Reads measurement data (eCO2 and TVOC) from the CSS811 sensor.
- Parameters
- 
         [out] eco2The eCO2 level read from the sensor [out] tvocThe TVOC level read from the sensor 
- Returns
- Returns zero on OK, non-zero otherwise
        Definition at line
        
         319
        
        of file
        
         ccs811.c
        
        .
       
References I2C_TransferSeq_TypeDef::addr , BOARD_gasSensorWake() , BOARD_i2cBusSelect() , I2C_TransferSeq_TypeDef::buf , CCS811_ADDR_ALG_RESULT_DATA , CCS811_ERROR_I2C_TRANSACTION_FAILED , CCS811_OK , I2C_TransferSeq_TypeDef::data , I2C_TransferSeq_TypeDef::flags , I2C_FLAG_WRITE_READ , I2CSPM_Transfer() , i2cTransferDone , and I2C_TransferSeq_TypeDef::len .
| uint32_t CCS811_getRawData | ( | uint16_t * | 
            current,
            | 
| uint16_t * | 
            rawData
            | ||
| ) | 
Gets the latest readings from the sense resistor of the CSS811 sensor.
- Parameters
- 
         [out] currentThe value of current through the sensor [out] rawDataThe raw ADC reading of the voltage across the sensor with the selected current 
- Returns
- Returns zero on OK, non-zero otherwise
        Definition at line
        
         374
        
        of file
        
         ccs811.c
        
        .
       
References I2C_TransferSeq_TypeDef::addr , BOARD_gasSensorWake() , BOARD_i2cBusSelect() , I2C_TransferSeq_TypeDef::buf , CCS811_ADDR_RAW_DATA , CCS811_ERROR_I2C_TRANSACTION_FAILED , CCS811_OK , I2C_TransferSeq_TypeDef::data , I2C_TransferSeq_TypeDef::flags , I2C_FLAG_WRITE_READ , I2CSPM_Transfer() , i2cTransferDone , and I2C_TransferSeq_TypeDef::len .
| uint32_t CCS811_getStatus | ( | uint8_t * | 
            status
            | ) | 
Reads the status of the CSS811 sensor.
- Parameters
- 
         [out] statusThe content of the CSS811 Status Register 
- Returns
- Returns zero on OK, non-zero otherwise.
        Definition at line
        
         136
        
        of file
        
         ccs811.c
        
        .
       
References CCS811_ADDR_STATUS , and CCS811_readMailbox() .
Referenced by CCS811_isDataAvailable() .
| uint32_t CCS811_init | ( | void | 
            | ) | 
Initializes the chip and performs firmware upgrade if required.
- Returns
- Returns zero on OK, non-zero otherwise
        Definition at line
        
         61
        
        of file
        
         ccs811.c
        
        .
       
References BOARD_gasSensorEnable() , BOARD_gasSensorWake() , CCS811_ERROR_INIT_FAILED , CCS811_getHardwareID() , CCS811_OK , and UTIL_delay() .
| bool CCS811_isDataAvailable | ( | void | 
            | ) | 
Checks if new measurement data available.
- Returns
- True if new data available, otherwise false
        Definition at line
        
         152
        
        of file
        
         ccs811.c
        
        .
       
References CCS811_getStatus() , and CCS811_OK .
| uint32_t CCS811_readMailbox | ( | uint8_t | 
            id,
            | 
| uint8_t | 
            length,
            | ||
| uint8_t * | 
            data
            | ||
| ) | 
Reads data from a specific Mailbox address.
- Parameters
- 
         [in] idThe address of the Mailbox register [in] lengthThe number of bytes to read [out] dataThe data read from the sensor 
- Returns
- Returns zero on OK, non-zero otherwise
        Definition at line
        
         270
        
        of file
        
         ccs811.c
        
        .
       
References I2C_TransferSeq_TypeDef::addr , BOARD_gasSensorWake() , BOARD_i2cBusSelect() , I2C_TransferSeq_TypeDef::buf , CCS811_ERROR_I2C_TRANSACTION_FAILED , CCS811_OK , I2C_TransferSeq_TypeDef::data , I2C_TransferSeq_TypeDef::flags , I2C_FLAG_WRITE_READ , I2CSPM_Transfer() , i2cTransferDone , and I2C_TransferSeq_TypeDef::len .
Referenced by CCS811_dumpRegisters() , CCS811_getHardwareID() , CCS811_getStatus() , and CCS811_startApplication() .
| uint32_t CCS811_setEnvData | ( | int32_t | 
            tempData,
            | 
| uint32_t | 
            rhData
            | ||
| ) | 
Writes temperature and humidity values to the environmental data regs.
- Parameters
- 
         [in] tempDataThe environmental temperature in milli-Celsius [in] rhDataThe relative humidity in milli-percent 
- Returns
- Returns zero on OK, non-zero otherwise
        Definition at line
        
         915
        
        of file
        
         ccs811.c
        
        .
       
References I2C_TransferSeq_TypeDef::addr , BOARD_gasSensorWake() , BOARD_i2cBusSelect() , I2C_TransferSeq_TypeDef::buf , CCS811_ADDR_ENV_DATA , CCS811_ERROR_I2C_TRANSACTION_FAILED , CCS811_OK , I2C_TransferSeq_TypeDef::data , I2C_TransferSeq_TypeDef::flags , I2C_FLAG_WRITE , I2CSPM_Transfer() , i2cTransferDone , and I2C_TransferSeq_TypeDef::len .
| uint32_t CCS811_setMeasureMode | ( | uint8_t | 
            measMode
            | ) | 
Sets the measurement mode of the CSS811 sensor.
- Parameters
- 
         [in] measModeThe desired measurement mode 
- Returns
- Returns zero on OK, non-zero otherwise
        Definition at line
        
         472
        
        of file
        
         ccs811.c
        
        .
       
References I2C_TransferSeq_TypeDef::addr , BOARD_gasSensorWake() , BOARD_i2cBusSelect() , I2C_TransferSeq_TypeDef::buf , CCS811_ADDR_MEASURE_MODE , CCS811_ERROR_I2C_TRANSACTION_FAILED , CCS811_OK , I2C_TransferSeq_TypeDef::data , I2C_TransferSeq_TypeDef::flags , I2C_FLAG_WRITE , I2CSPM_Transfer() , i2cTransferDone , and I2C_TransferSeq_TypeDef::len .
| uint32_t CCS811_softwareReset | ( | void | 
            | ) | 
Performs software reset on the CCS811.
- Returns
- Returns zero on OK, non-zero otherwise
        Definition at line
        
         423
        
        of file
        
         ccs811.c
        
        .
       
References I2C_TransferSeq_TypeDef::addr , BOARD_gasSensorWake() , BOARD_i2cBusSelect() , I2C_TransferSeq_TypeDef::buf , CCS811_ADDR_SW_RESET , CCS811_ERROR_I2C_TRANSACTION_FAILED , CCS811_OK , I2C_TransferSeq_TypeDef::data , I2C_TransferSeq_TypeDef::flags , I2C_FLAG_WRITE , I2CSPM_Transfer() , i2cTransferDone , and I2C_TransferSeq_TypeDef::len .
| uint32_t CCS811_startApplication | ( | void | 
            | ) | 
Switches the CSS811 chip from boot to application mode.
- Returns
- Returns zero on OK, non-zero otherwise
        Definition at line
        
         227
        
        of file
        
         ccs811.c
        
        .
       
References CCS811_ADDR_STATUS , CCS811_ERROR_APPLICATION_NOT_PRESENT , CCS811_ERROR_NOT_IN_APPLICATION_MODE , and CCS811_readMailbox() .