Actually works, and with mbed os 5 latest

Dependents:   CCS811-TEST Mbed-Connect-Cloud-Demo Mbed-Connect-Cloud-Demo HTTP-all-sensors ... more

Fork of CCS811 by MtM+

Committer:
andcor02
Date:
Thu Oct 19 11:24:59 2017 +0000
Revision:
2:64a96d555ef0
Parent:
1:4acc5b63a984
changed constructor, better compatibility

Who changed what in which revision?

UserRevisionLine numberNew contents of line
johnathanlyu 0:b5dbfc21185d 1 #ifndef CCS811_H
johnathanlyu 0:b5dbfc21185d 2 #define CCS811_H
johnathanlyu 0:b5dbfc21185d 3
johnathanlyu 0:b5dbfc21185d 4 //CCS811 register define
andcor02 1:4acc5b63a984 5 #define CCS811_I2C_ADDR 0xB6 //This is already left shifted 0x5B, if using other address, should be 0xB4 which is 0x5A left shifted.
johnathanlyu 0:b5dbfc21185d 6 #define CCS811_REG_STATUS 0x00 //Status.
johnathanlyu 0:b5dbfc21185d 7 #define CCS811_REG_MEAS_MODE 0x01 //Mesurement mode and conditions register.
johnathanlyu 0:b5dbfc21185d 8 #define CCS811_REG_ALG_RESULT_DATA 0x02 //Algorithm result. 2 bytes co2 ppm next 2 bytes ppb VOC level.
johnathanlyu 0:b5dbfc21185d 9 #define CCS811_REG_RAW_DATA 0x03 //Raw ADC data.
johnathanlyu 0:b5dbfc21185d 10 #define CCS811_REG_ENV_DATA 0x05 //Temperature and humidity data can be write to enavle compensation.
johnathanlyu 0:b5dbfc21185d 11 #define CCS811_REG_NTC 0x06 //Provides the voltage across the reference registor and the voltage across the NTC resistor.
johnathanlyu 0:b5dbfc21185d 12 #define CCS811_REG_THRESHOLDS 0x10 //Thresholds for operation when interrupts are only generated when eCO2 ppm crosses a threshold.
johnathanlyu 0:b5dbfc21185d 13 #define CCS811_REG_BASELINE 0x11 //The encoded current baseline value can be read.A previously saved encoded baseline can be written.
johnathanlyu 0:b5dbfc21185d 14 #define CCS811_REG_HW_ID 0x20 //Hardware ID. The value is 0x81.
johnathanlyu 0:b5dbfc21185d 15 #define CCS811_REG_HW_VERSION 0x21 //Hardware version. The value is 0x1X.
johnathanlyu 0:b5dbfc21185d 16 #define CCS811_REG_BOOT_VERSION 0x23 //Firmware boot version. The First 2 bytes contain the firmware version number for the boot code.
johnathanlyu 0:b5dbfc21185d 17 #define CCS811_REG_APP_VERSION 0x24 //Firmware application version. The first 2 bytes contain the firmware version number for the application code.
johnathanlyu 0:b5dbfc21185d 18 #define CCS811_REG_ERROR_ID 0xE0 //Error ID. When the status register reports and error its source is lcated in this register.
johnathanlyu 0:b5dbfc21185d 19 #define CCS811_REG_APP_START 0xF4 //Application start. Used to transition the CCS811 state from boot to application mode, a write with no data is required. Before performing a write to APP_START the Status register should be accessed to check if there is a valid application present.
johnathanlyu 0:b5dbfc21185d 20 #define CCS811_REG_SW_RESET 0xFF //If the correct 4 byres (0x11, 0xE5, 0x72, 0x8A)are written to this register in a single sequence the device will reset and return to BOOT bode.
johnathanlyu 0:b5dbfc21185d 21
johnathanlyu 0:b5dbfc21185d 22 //mode setting
johnathanlyu 0:b5dbfc21185d 23 #define CCS811_MEASUREMENT_MODE0 0x00 //Idle(Measurements are disabled in this mode).
johnathanlyu 0:b5dbfc21185d 24 #define CCS811_MEASUREMENT_MODE1 0x10 //Constant power mode, IAQ measurement every second.
johnathanlyu 0:b5dbfc21185d 25 #define CCS811_MEASUREMENT_MODE2 0x20 //Pulse heating mode IAQ measurement every 10 seconds.
johnathanlyu 0:b5dbfc21185d 26 #define CCS811_MEASUREMENT_MODE3 0x30 //Low power pulse heating mode IAQ measurement every 60 seconds.
johnathanlyu 0:b5dbfc21185d 27 #define CCS811_MEASUREMENT_MODE4 0x40 //Constant power mode, sensor measurement every 250ms. 1xx: Reserved modes (For future use).
johnathanlyu 0:b5dbfc21185d 28
johnathanlyu 0:b5dbfc21185d 29 //Interrupt control
johnathanlyu 0:b5dbfc21185d 30 #define CCS811_INT_DATARDY 0x08 //At the end of each measurement cycle (250ms, 1s, 10s, 60s) a flag is set in the STATUS register regardless of the setting of this bit.
johnathanlyu 0:b5dbfc21185d 31 #define CCS811_INT_THRESH 0x04 //0: Interrupt mode (if enabled) operates normally 1: Interrupt mode (if enabled) only asserts the nINT signal (driven low) if the new ALG_RESULT_DATA crosses one of the thresholds set in the THRESHOLDS register by more than the hysteresis value (also in the THRESHOLDS register).
johnathanlyu 0:b5dbfc21185d 32
johnathanlyu 0:b5dbfc21185d 33 #include "mbed.h"
johnathanlyu 0:b5dbfc21185d 34
johnathanlyu 0:b5dbfc21185d 35 class CCS811 {
johnathanlyu 0:b5dbfc21185d 36 public:
andcor02 2:64a96d555ef0 37 CCS811(PinName sda, PinName scl);
johnathanlyu 0:b5dbfc21185d 38 void init();
johnathanlyu 0:b5dbfc21185d 39 int setMeasureMode(char mode);
johnathanlyu 0:b5dbfc21185d 40 int readData(uint16_t *ECO2, uint16_t *TVOC);
johnathanlyu 0:b5dbfc21185d 41 bool checkHW();
johnathanlyu 0:b5dbfc21185d 42 bool softRest();
andcor02 1:4acc5b63a984 43 bool readstatus();
andcor02 1:4acc5b63a984 44 bool readmeas();
andcor02 1:4acc5b63a984 45 bool readerror();
johnathanlyu 0:b5dbfc21185d 46 protected:
andcor02 2:64a96d555ef0 47 I2C _i2c;
johnathanlyu 0:b5dbfc21185d 48 private:
johnathanlyu 0:b5dbfc21185d 49 };
johnathanlyu 0:b5dbfc21185d 50
johnathanlyu 0:b5dbfc21185d 51
johnathanlyu 0:b5dbfc21185d 52 #endif