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

I2C write byte is not sending bytes #236

Open
lefebvresam opened this issue Feb 3, 2024 · 3 comments
Open

I2C write byte is not sending bytes #236

lefebvresam opened this issue Feb 3, 2024 · 3 comments

Comments

@lefebvresam
Copy link

When I try this:

RetCode_t RA8875::GT911_WriteConfig(GTConfig *config){
    // char address[2] = { 0 };
    // address[0] = GTP_REG_CONFIG_DATA >> 8; // add H
    // address[1] = GTP_REG_CONFIG_DATA & 0xFF; // add L
    // int err = m_i2c->write(m_addr, address, 2, true);
    // if (err) {
    //     ERR("I2C result: %d", err);
    // }
    INFO("GTConfig size: %u", sizeof(GTConfig));
    m_i2c->lock();
    m_i2c->start();
    m_i2c->write_byte((uint8_t)(m_addr+1));
    m_i2c->write_byte((uint8_t)GTP_REG_CONFIG_DATA >> 8);
    m_i2c->write_byte((uint8_t)GTP_REG_CONFIG_DATA & 0xFF);
    for (int i = 0; i < sizeof(GTConfig); i++) {
        int err = m_i2c->write_byte(*((uint8_t*)config+i));
        if (err) {
            ERR("I2C result: %d", err);
        }  
    }  
    m_i2c->stop();
    m_i2c->unlock();
    // err = m_i2c->write(m_addr, (char*)config, sizeof(GTConfig));
    return noerror;
}

I get this:

New25

@multiplemonomials
Copy link
Collaborator

Hmm, are any of those I2C calls returning an error code?

@JohnK1987
Copy link
Member

Hmm, are any of those I2C calls returning an error code?

@lefebvresam any comment?

@lefebvresam
Copy link
Author

I omitted this issue by not longer using those function calls.
I think the bug in those calls is still there and should be further investigated.

I now use this implementation which is working correctly for my application:

RetCode_t RA8875::GT911_WriteConfig(GTConfig *config){
    GTchecksum cs;
    GT911_ReadChecksum(&cs);
    INFO("Read checksum: 0x%02X", cs.value);
    uint8_t cs_calc = GT911_CalcChecksum((uint8_t *)config+2, sizeof(GTConfig)-2);
    INFO("Calc checksum: 0x%02X", cs_calc);
    if (!configLoaded) {
        ERR("Config has not been loaded");
        return bad_parameter;
    }
    if (cs.value != cs_calc) {  // config has been changed
        int err = m_i2c->write(m_addr, (char*)config, sizeof(GTConfig));
        if (err) {
            ERR("I2C result: %d", err);
            return bad_parameter;
        }
        cs.value = cs_calc;
        cs.fresh = 1; // configuration updated 
        GT911_WriteChecksum(&cs);
        INFO("Config has been written correctly");   
        return noerror;
    }
    INFO("No differences in config");
    return noerror;
}

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

3 participants