Open WBosonic opened 2 months ago
@WBosonic, thanks for the report. I agree this looks wrong. However, are you sure it's an SP (stop) you see between the write operations? I'd expect a SR (repeated start), triggered by https://github.com/rp-rs/rp-hal/blob/main/rp2040-hal/src/i2c/controller.rs#L294:
if first_byte {
if !first_transaction {
w.restart().enable();
}
first_byte = false;
}
@ithinuel, if I read the git history correctly, that was added in https://github.com/rp-rs/rp-hal/pull/764. Do you remember why?
Ah yes it is an SR (I encountered this bug a while ago and misremembered).
From what I see the user facing I2C transaction does not actually check if the transaction type is the same as the one before.
Ah yes it is an SR (I encountered this bug a while ago and misremembered).
From what I see the user facing I2C transaction does not actually check if the transaction type is the same as the one before.
If I understand the datasheet correctly, it doesn't need to:
1 - If IC_RESTART_EN is 1, a RESTART is issued before the data is sent/received (according to the value of CMD), regardless of whether or not the transfer direction is changing from the previous command; if IC_RESTART_EN is 0, a STOP followed by a START is issued instead. 0 - If IC_RESTART_EN is 1, a RESTART is issued only if the transfer direction is changing from the previous command; if IC_RESTART_EN is 0, a STOP followed by a START is issued instead.
So the fix could be as easy as removing w.restart().enable();
entirely?
Yes, provided that ic_restart_en
is set (which it is).
The sensor I am writing a driver for requires I2C communication of the form where
INDEX
is some internal 16 bit register and DATA can be any number of bytes.The I2C transaction contract states:
Therefore I would expect this code to work
Instead it appears an SP is sent between the two
Write
operations forcing unnecessary copies:Given that I need to send around 80kB of data this seems wasteful.