はっくはっくキッチン
Hack Hack Kitchen

ccs811.asm

 2021/12/25

A device driver of CCS811-Air quality sensor for AVR. This code is a part of pAVRlib.

Requirement

Subroutines

void CCS811_RESET() (in: (none), out: (none))

resets CCS811 (via nRESET). To use this routine, you need to define CCS811_USE_RESET. To define the pin for nRESET, use CCS811_RESET_DDR, CCS811_RESET_PORT and CCS811_RESET_PINNUM.

For example, to use PB6-pin for nRESET:

    .define CCS811_USE_RESET
    .equ CCS811_RESET_DDR	= DDRB
    .equ CCS811_RESET_PORT	= PORTB
    .equ CCS811_RESET_PINNUM	= 6

char CCS811_SEARCH() (in: (none), out: r24)

This routine searches CCS811. This routine returns r24 < 0x80 (positive value as a signed char) as the address of CCS811, or r24 $\ge$ 0x80 (negative value as a signed char) if CCS811 is not found.

Known Issues

  • Error handling of I²C is not complete.

  • Only one device can be found.

char CCS811_INITIALIZE(addr) (in: r24, out: r24)

initializes CCS811. addr (r24) is a I²C-Address of CCS811. It returns a status value (r24) as a result.

Initialize is succeeded if r24 = 0. r24 = -1 (0xff) means "no valid application" (see datasheet of CCS811 for more details of "application"). r24 = -2 (0xfe) means "invalid firmware mode".

unsigned int CCS811_WRITE(char addr, char ccs811_reg, char bytes, char *data)

writes data to CCS811. For example, the data in r0, r1, … will be sent if you call this routine with r19:r18 = 0,

in

r24 I²C-Address of CCS811
r22 Register of CCS811 to write
r20 the number of bytes to write
r19:r18 start address of data to be sent

out

r25 TWI status
r24 (unchanged)

unsigned int CCS811_READ(char addr, char ccs811_reg, char bytes, char *data)

reads data from CCS811. For example, the received data will be stored in r0, r1, … if you call this routine with r19:r18 = 0.

in

r24 I²C-Address of CCS811
r22 Register of CCS811 to read
r20 the number of bytes to read
r19:r18 start address of data to be stored

out

r25 TWI status
r24 (unchanged)

Examples

The following programs reads data from CCS811 and show the received data.

../examples/ccs811-test.asm

The test program for ccs811-asm (asm version).

This program reads data from CCS811 and show the received data via USART like this:

$ dterm /dev/ttyUSB0 4800
# Hallo CCS811
# CCS811 found at 0x5A
# Waiting for the first data ....
# Entering interrupt mode
eCO2:   406 ppm, eTVOC:     0 ppb [ 01 96 00 00 98 00 07 23 ]
eCO2:   409 ppm, eTVOC:     1 ppb [ 01 99 00 01 98 00 07 21 ]
eCO2:   413 ppm, eTVOC:     1 ppb [ 01 9D 00 01 98 00 07 20 ]
eCO2:   413 ppm, eTVOC:     1 ppb [ 01 9D 00 01 98 00 07 20 ]
eCO2:   406 ppm, eTVOC:     0 ppb [ 01 96 00 00 98 00 07 23 ]
eCO2:   408 ppm, eTVOC:     1 ppb [ 01 98 00 01 98 00 07 22 ]
 :
 :

To compile this file, the following files are required (These files are parts of the pAVRlib).

See also: examples/README.org

../examples-C/ccs811-test.c

The test program for ccs811.asm (C version).

To compile this file, the following files are required (These files are parts of the pAVRlib).

See also: examples-C/README.org