i2c_write_dt stop

Hello,
trying this and that with a qwiic relay, first a test on i2ccl then VS using a 9160DK.
(i2ccl -> pip install i2cdriver)

i2ccl /dev/ttyUSB0 w 0x18 5 r 0x18 1


returns a status of 0x00 that relay is not activated.

then in VS,

uint8_t wBuff[1] = {0x05};
uint8_t rBuff = 0x00;
uint8_t a = 0;

a = i2c_write_read_dt(&dev_i2c, wBuff, sizeof(wBuff), &rBuff, sizeof(rBuff));
if (a != 0) {
        printk("I2C error %d\n", a);
}
printk("Status: %X\n", rBuff);


Status: 0
same as i2ccl

Then when trying to activate the relay with a write,

i2ccl /dev/ttyUSB0 w 0x18 1 p


the relay clicks on ok

But in VS,

uint8_t wArray[1] = {0x01};
uint8_t a = 0;

a = i2c_write_dt(&dev_i2c, wArray, 1);
if (a != 0) {
    printk("I2C write failed with error %d\n", a);
}


There is no click response.
The difference seems to be that i2ccl is sending stop 'p' at the end of the write which Zephyr might not be doing the same.
When trying write and read 0x05 status separately in VS, the result is ok and same as i2ccl without stop.
If it is the missing stop, how best then to get a stop into i2c_write_dt?

thank-you,

  • In an ideal world I would have time to try this, but unfortunately I don't. Looking at what is working I would expect something like this to work:

    // read
    msg[0].buf = value 5?;
    msg[0].len = 1;
    msg[0].flags = I2C_MSG_WRITE;

    msg[1].buf = buf;
    msg[1].len = 1;
    msg[1].flags = I2C_MSG_RESTART | I2C_MSG_READ | I2C_MSG_STOP;

    return i2c_transfer_dt(spec, msg, 2);

    // write

    msg[0].buf = value 1?;
    msg[0].len = 1;
    msg[0].flags = I2C_MSG_WRITE | I2C_MSG_STOP;

    return i2c_transfer_dt(spec, msg, 1);

    Kenneth

  • Made the slight change to the previous try of i2c_transfer_dt.

    uint8_t wArray[1] = {0x01}; // Register address to read from
    uint8_t a = 0;
    
    struct i2c_msg msgs[1] = {
        {
            .buf = wArray,
            .len = 1,
            .flags = I2C_MSG_WRITE | I2C_MSG_STOP,
        },
    };
    
    a = i2c_transfer_dt(&dev_i2c, msgs, 1);
    if (a != 0) {
        printk("I2C transfer failed with error %d\n", a);
    }else{
        printk("a %x \n", a);
    }

    Same result and no relay click.
    Will try i2c_write_dt() again.
    From the logic output, it seems to have the right structure.

    thank-you,

  • Better success using i2c_write_dt() on a thingy:53.

    thank-you,

Related