void CCS811Init()
{
u8 idCount = 0; // count the correct times of id.
CCS811_CS_ON(); //nWAKE pin is asserted at least 50μs before the transaction and kept asserted throughout,nWAKE pin is active low
delay_ms(STEP_DELAY);
// get CCS811 device id,when addr pin connect to GND and the id is 0x81(129)
while( FlagGetId)
{
CCS811_ReadI2C(CCS811_Add, 0x20, Information, 1); //Read CCS's information ,ID
if(Information[0] == 0x81)
{
if(++idCount == n)
{
FlagGetId = 0;
}
else
{
printf("id=%d,correct %d!rn", Information[0], idCount);
}
}
else
{
printf("id=%d,incorrect,continuing...rn", Information[0]);
}
delay_ms(STEP_DELAY);
}
printf("id correct,initing...rn");
delay_ms(STEP_DELAY);
CCS811_ReadI2C(CCS811_Add, 0x23, &Information[1], 2); //FW_Boot_Version
delay_ms(STEP_DELAY);
CCS811_ReadI2C(CCS811_Add, 0x24, &Information[3], 2); //FW_App_Version
delay_ms(STEP_DELAY);
CCS811_ReadI2C(CCS811_Add, 0x00, &Status, 1); //Firstly the status register is read and the APP_VALID flag is checked.
delay_ms(STEP_DELAY);
// if there is valid application firmware loaded
if(Status & 0x10)
{
while(!(Status & 0x80)) // if firmware not in application mode but boot mode.
{
CCS811_WriteI2C_byte(CCS811_Add, 0xF3, 0xF0); // Application Verify
printf("trying to transition the CCS811 state from boot to application mode...rn");
CCS811_MWriteI2C_byte(CCS811_Add, 0xF4, &temp, 0); //Used to transition the CCS811 state from boot to application mode, a write with no data is required.
delay_ms(STEP_DELAY);
CCS811_ReadI2C(CCS811_Add, 0x00, &Status, 1);
delay_ms(STEP_DELAY);