Coder Social home page Coder Social logo

Comments (2)

maarten-pennings avatar maarten-pennings commented on July 23, 2024

Hi @iKlask
You might be right, the buf[5]=0 is fishy.
Do you have a proposed fix?

from ccs811.

dodo041 avatar dodo041 commented on July 23, 2024

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):

  • What was the issue you encountered with the returned status byte, when using firmware version < 2.0.0? @iKlask pointed out, that he did not have problems with versions lower than that.
  • Why was it sufficient for you to assume, that there's no error, when
    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?
  • In case we indeed look for an error, and the status from CCS811_ALG_RESULT_DATA indeed was wrong, was the error id byte wrong as well? I assume it was, since there would be no point in attempting to set the byte to 0. That would mean, we'd need to update the error byte as described above, but only in case it's wrong just as the status byte is.

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!

from ccs811.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.