Forum: Mikrocontroller und Digitale Elektronik Problem beim Auslesen des Air Quality Sensors SGP30


von M. G. (ixil96)


Lesenswert?

Hallo!
Ich bastle gerade mit dem Sensirion SGP30 Sensor herum und habe ein 
Problem beim Lesen der Air Quality (CO2eq und TVOC) Werte.
Datenblatt: 
https://www.sensirion.com/fileadmin/user_upload/customers/sensirion/Dokumente/9_Gas_Sensors/Sensirion_Gas_Sensors_SGP30_Datasheet_EN.pdf


Die I2C Kommunikation funktioniert, das Auslesen von ID, Feature Set 
Version und Measure Test klappt.

Wie im Datenblatt beschrieben...
 Sending an “Init_air_quality” command starts the air quality 
measurement. After the “Init_air_quality”command, a 
“Measure_air_quality” command has to be sent in regular intervals of 1s 
to ensure proper operation of the dynamic baseline compensation 
algorithm. The sensor responds with 2 data bytes (MSB first) and 1 CRC 
byte for each of the two preprocessed air quality signals in the order 
CO2eq (ppm) and TVOC (ppb). For the first 15s after the 
“Init_air_quality” command the sensor is in an initialization phase 
during which a “Measure_air_quality” command returns fixed values of 400 
ppm CO2eq and 0 ppb TVOC.

...sende ich zuerst ein Init_air_quality command und anschließend ein 
Measure_air_quality command. Gefolgt von einem readout von 6 Bytes.

Nach dem 1. readout bekomme ich 0x0190 (dez 400) und 0x0014 (dez 20) als 
Werte für CO2eq und TVOC. Die 400 stimmen, aber für TVOC sollte ich 0x00 
bekommen.

Nach dem 1. readout springe ich in die Endlosschleife und führe 1x pro 
Sekunde ein readout von CO2eq und TVOC aus. Hier bleibe ich aber bei 3. 
readout hängen ->
1
        while((!I2C_CHECK_INTR_RX(I2C_INTR_RX_NOT_EMPTY)) &&
2
              (!I2C_CHECK_INTR_MASTER(I2C_INTR_MASTER_I2C_ARB_LOST |
3
                                                  I2C_INTR_MASTER_I2C_BUS_ERROR)))

Hat jemand eine Idee was hier falsch läuft?

Hier noch ein Codeausschnitt meiner Routine:
1
/* Send InitAirQuality command to start the air quality measurment 
2
     * 1. Send Init_air_quality command to start air quality measurment */
3
    I2C_I2CMasterSendStart(DeviceAddress,I2C_I2C_WRITE_XFER_MODE);          // Initialize a transaction for writing
4
    I2C_I2CMasterWriteByte(InitAirQuality_MSB);                             // Send MSB command
5
    I2C_I2CMasterWriteByte(InitAirQuality_LSB);                             // Send LSB command
6
    I2C_I2CMasterSendStop();                                                // I2C Stop
7
    
8
    /* 2. Send measure_air_quality command */
9
    I2C_I2CMasterSendStart(DeviceAddress,I2C_I2C_WRITE_XFER_MODE);          // Initialize a transaction for writing
10
    I2C_I2CMasterWriteByte(MeasureAirQuality_MSB);                          // Send LSB command
11
    I2C_I2CMasterWriteByte(MeasureAirQuality_LSB);                          // Send LSB command
12
    I2C_I2CMasterSendStop();                                                // I2C Stop                                        
13
    CyDelay(10);                                                            // wait 10ms
14
    
15
    /* Readout 6 bytes: 1. CO2 (MSB, LSB, CRC) 2. TVOC (MSB, LSB, CRC) */
16
    I2C_I2CMasterSendStart(DeviceAddress,I2C_I2C_READ_XFER_MODE);           // Initialize a transaction for reading
17
    airQuality[0] = I2C_I2CMasterReadByte(I2C_I2C_ACK_DATA);                // Read from register MSB
18
    airQuality[1] = I2C_I2CMasterReadByte(I2C_I2C_ACK_DATA);                // Read from register LSB
19
    airQuality[2] = I2C_I2CMasterReadByte(I2C_I2C_ACK_DATA);                // Read from register CRC
20
    airQuality[3] = I2C_I2CMasterReadByte(I2C_I2C_ACK_DATA);                // Read from register MSB
21
    airQuality[4] = I2C_I2CMasterReadByte(I2C_I2C_ACK_DATA);                // Read from register LSB
22
    airQuality[5] = I2C_I2CMasterReadByte(I2C_I2C_NAK_DATA);                // Read from register CRC
23
    I2C_I2CMasterSendStop();                                                // I2C Stop
24
    asm("nop");
25
26
    for(;;)
27
    {
28
        CyDelay(1000);
29
        /* Send measure_air_quality command every second */
30
        I2C_I2CMasterSendStart(DeviceAddress,I2C_I2C_WRITE_XFER_MODE);          // Initialize a transaction for writing
31
        I2C_I2CMasterWriteByte(MeasureAirQuality_MSB);                          // Send MSB command
32
        I2C_I2CMasterWriteByte(MeasureAirQuality_LSB);                          // Send LSB command
33
        I2C_I2CMasterSendStop();                                                // I2C Stop
34
                                                    
35
        CyDelay(10);                                                            // wait 10ms
36
        
37
        /* Readout 6 bytes: 1. CO2 (MSB, LSB, CRC) 2. TVOC (MSB, LSB, CRC) */
38
        I2C_I2CMasterSendStart(DeviceAddress,I2C_I2C_READ_XFER_MODE);           // Initialize a transaction for reading
39
        airQuality[0] = I2C_I2CMasterReadByte(I2C_I2C_ACK_DATA);                // Read from register MSB
40
        airQuality[1] = I2C_I2CMasterReadByte(I2C_I2C_ACK_DATA);                // Read from register LSB
41
        airQuality[2] = I2C_I2CMasterReadByte(I2C_I2C_ACK_DATA);                // Read from register CRC
42
        airQuality[3] = I2C_I2CMasterReadByte(I2C_I2C_ACK_DATA);                // Read from register MSB
43
        airQuality[4] = I2C_I2CMasterReadByte(I2C_I2C_ACK_DATA);                // Read from register LSB
44
        airQuality[5] = I2C_I2CMasterReadByte(I2C_I2C_NAK_DATA);                // Read from register CRC
45
        I2C_I2CMasterSendStop();                                                // I2C Stop
46
        asm("nop");
47
    }

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.