Open iKlask opened 5 years ago
Hi @iKlask You might be right, the buf[5]=0 is fishy. Do you have a proposed fix?
Hi @maarten-pennings, I'm working with an adaptation of your code for the CCS811 sensor, written in plain C. Checking the logics, I came across the same issue which was presented by the author. I'm thinking about a fix for the issue, since the else case in line if( ok && stat==CCS811_ERRSTAT_OK ) ok= i2cread(CCS811_ALG_RESULT_DATA,8,buf); else buf[5]=0;
definitely seems wrong, since there's no point in overwriting the byte buf[5] containing the error information, when the status byte suggests the existence of an error.
My idea was to read the error id from the error register, when the error bit in the status register is set. So (as before) you read the status register only, check for existing errors, and if the error bit in the status register is set, read the error register e.g. with ok= i2cread(CCS811_ERROR_ID,8,buf);
(with CCS811_ERROR_ID being the address 0xE0 in the application register), and then just proccessing the error id as needed.
Afterwards replace the status byte from ALG data with the previously read "correct" status, and if needed the errror id byte with the read error id, otherwise (if there's no error and the error id byte is also errnoeous) set it to 0.
Before going along with this simple fix, I'd like you to supply me with some information (if you still can remember, since the issue is opened for almost 3 years now):
stat == CCS811_ERRSTAT_OK
returned true? If the statement was true, this should only indicate, that 1. the ALG data is ready, 2. the firmware is valid, and 3. the firmware is in application mode: #define CCS811_ERRSTAT_OK (CCS811_ERRSTAT_DATA_READY | CCS811_ERRSTAT_APP_VALID | CCS811_ERRSTAT_FW_MODE)
An error would only be clearly indicated if the bit at CCS811_ERRSTAT_ERROR is set. In my opinion you wanted to have something like this statement:
status & CCS811_ERRSTAT_ERROR
(or the opposite: we'd have no error when
status & ~CCS811_ERRSTAT_ERROR
returns true)
Did you even want to check for an existing error, or just for an OK running application?Maybe I'm leaving something obvious and important out of my considerations, but for now this seems like the only plausible way of a workaround, if there really were any errors with that firmware versions and the status bytes in ALG data.
Groetjes in het mooie Nederland!
I had an issue with my cjmcu-811 on firmware 1100. It kept throwing the following at startup:
This seemed odd because it meant it was in application mode (good), application firmware loaded (good), data ready (good), and some error in the ERROR_ID... but none of the other flags were being thrown even though it thinks there's an error in ERROR_ID?
So I took out the debugger and found this code block:
The important part is the third line. If i2cread() passed and stat==CCS811_ERRSTAT_OK, then read the whole CCS811_ALG_RESULT_DATA into buff. Otherwise... just zero out the ERROR_ID part of buff at buf[5]? Why?
My issue ended up being a poorly soldered zero-ohm resistor between pins 4 and 5 on the CCS811 package. These are the PWM and Sense pins which need a connection for sensing the Heater current. Since these were not connected the board was throwing a
CCS811_ERRSTAT_HEATER_SUPPLY
error in ERROR_ID but I was never getting these flags printed for me. Correct me if I'm wrong, but it seems as if your code doesn't read the ERROR_ID byte unless there are no errors reported by status? If there's an error in status, it doesn't read anything into buff.A second note, this whole workaround for v1100 is supposedly because the status register from
i2cread(CCS811_ALG_RESULT_DATA,8,buf);
reads incorrectly in firmware v1100. However, my status register seemed to read fine on firmware v1100 fromCCS811_ALG_RESULT_DATA
.