How to remove start bit from an I2C transfer in zephyr

Hello,

I am developing a driver for the vl53l5cx TOF sensor from ST, however their sequential write format looks as such:

This is problematic for me since I can get the address, and register index sent correctly with the stop bit at the end, however zephyr always sends a start bit for the data being written and I have not found a way to disable this. How can I do this using sdk 1.9.1?

Thanks,

Jacob

Parents
  • Hello!

    What function(s) are you currently using when you try to write? i2c_write? i2c_burst_write? i2c_transfer?

    It seems to me that what you want is similar to i2c_burst_write, but with a stop condition after sending the buffer address, you might have to set up your write manually using i2c_transfer since you want this irregular formatting.

    Perhaps something like this:

    struct i2c_msg msg[2];

    msg[0].buf = &start_addr;
    msg[0].len = 1U;
    msg[0].flags = I2C_MSG_WRITE | I2C_MSG_STOP;

    msg[1].buf = (uint8_t *)buf;
    msg[1].len = num_bytes;
    msg[1].flags = I2C_MSG_WRITE | I2C_MSG_STOP;

    i2c_transfer(dev, msg, 2, dev_addr);

    Best regards,

    Einar

  • Aha, turns out that is exactly what I have done. But it still gives me a start bit before the data bytes. I removed the I2C_MSG_WRITE from the second message but still no luck.

    See here:

    Using:

    static inline int i2c_write_test(const struct device *dev, uint8_t *write_reg, uint8_t *write_buf, size_t num_write, uint16_t addr)
    {
    	struct i2c_msg msg[2];
    
    	msg[0].buf = write_reg;
    	msg[0].len = 2U;
    	msg[0].flags = I2C_MSG_WRITE | I2C_MSG_STOP;
    
    	msg[1].buf = write_buf;
    	msg[1].len = num_write;
    	msg[1].flags = I2C_MSG_STOP;
    
    	return i2c_transfer(dev, msg, 2, addr);
    }

  • Hm I see, that's strange.

    It seems odd to me that you're supposed to send data after a stop sequence with no start sequence.

    Looking at your sensor's data sheet, it says "All serial interface communications with the Time-of-Flight sensor must begin with a start condition." and "A message contains a series of bytes preceded by a start condition and followed by either a stop or repeated start (another start condition but without a preceding stop condition) followed by another message."

    Are you sure the P after the index bytes is really supposed to be a stop sequence, and not perhaps a repeated start sequence?

    -Einar

  • That's what I thought as well, it's strange that they wrote it in such a way. Perhaps it is an issue with the datasheet, I will contact ST about this. I will keep playing around with different variations to see what works. But yes it mentions here:

    That P is for stop and S is for start.

    Thanks,

    Jacob

Reply Children
Related