Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Some functions return timeout. #7

Open
rtek1000 opened this issue Feb 28, 2024 · 1 comment
Open

BUG: Some functions return timeout. #7

rtek1000 opened this issue Feb 28, 2024 · 1 comment

Comments

@rtek1000
Copy link

rtek1000 commented Feb 28, 2024

GSL1680 TS = GSL1680(true, true);

GSL1680::GSL1680(bool error, bool info)

12:58:02.129 -> GSL1680: Start boot up sequence
12:58:02.257 -> Toggle Wake
12:58:02.289 -> Clear reg
12:58:03.317 -> i2c write error: timeout
12:58:03.317 ->
12:58:03.317 -> Reset chip
12:58:04.314 -> i2c write error: timeout

  • Functions that have a loop to write different non-sequential addresses need to be stopped and started with each new register

https://github.com/Skallwar/GSL1680/blob/master/GSL1680.cpp

Timeout error:

void GSL1680::clear_reg()
{
    uint8_t REG[4] = {0xE0, 0x80, 0xE4, 0xE0};
    uint8_t DATA[4] = {0x88, 0x01, 0x04, 0x00};
    uint8_t TIMER[4] = {20, 5, 5, 20};

    Wire.beginTransmission(I2CADDR);

    int i;
    for (i = 0; i < 4; ++i) {
        Wire.write(REG[i]);
        Wire.write(DATA[i]);
        delay(TIMER[i]);
    }

    int r = Wire.endTransmission();
    if (r != 0){
        SERIAL_ERROR.print("i2c write error: "); SERIAL_ERROR.print(r); SERIAL_ERROR.print(" "); SERIAL_ERROR.println(REG[i], HEX);
    }

}

No timeout error:

void GSL1680::clear_reg()
{
    uint8_t REG[4] = {0xE0, 0x80, 0xE4, 0xE0};
    uint8_t DATA[4] = {0x88, 0x01, 0x04, 0x00};
    uint8_t TIMER[4] = {20, 5, 5, 20};

    int i;
    for (i = 0; i < 4; ++i) {
        Wire.beginTransmission(I2CADDR);
        Wire.write(REG[i]);
        Wire.write(DATA[i]);
        delay(TIMER[i]);
        int r = Wire.endTransmission();
        if (r != 0){
            SERIAL_ERROR.print("i2c write error: "); SERIAL_ERROR.print(r); SERIAL_ERROR.print(" "); SERIAL_ERROR.println(REG[i], HEX);
        }
    }
}

https://www.arduino.cc/reference/en/language/functions/communication/wire/endtransmission/

Returns

0: success.
1: data too long to fit in transmit buffer.
2: received NACK on transmit of address.
3: received NACK on transmit of data.
4: other error.
5: timeout

        uint8_t r = Wire.endTransmission();
        if (r != 0){
            if(r == 5) {
                SERIAL_ERROR.println("i2c write error: timeout");
            } else {
                SERIAL_ERROR.print("i2c write error: ");
                SERIAL_ERROR.print(r);
                SERIAL_ERROR.print(" ");
                SERIAL_ERROR.println(REG[i], HEX);
            }
            
            SERIAL_ERROR.println();
        }
@rtek1000
Copy link
Author

After correction it works wonderfully, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant