[En-Nut-Discussion] Missing possibility in the I2CBUS API

Harald Kipp harald.kipp at egnite.de
Tue Feb 19 13:06:42 CET 2013


Hi Uwe,

On 19.02.2013 12:29, Uwe Bonnes wrote:
> while most devices allow to read multiple I2C registers with some
> auto-increment scheme, Maxim for it's MAX44009 ambient light sensor decided
> to require another sequence:
> Start- Chip Address/Write - Write Register number - repeated start -
> Chip Address/Read - Read register content- Start- Chip Address/Write - Write
> Register next number - repeated start - Chip Address/Read - Read register
> content - Stop.
> This means multiple transactions without STOP during the sequence of
> transactions.

There is even more: PMBus allows to change the slave address after a
repeated start (see chapter 9 of the I2C specs.).

I assume, that not all I2C master hardware is able to support this,
neither the Maxim nor the PMBus scheme.


> The i2cbus API implemented in dev/i2cbus.c so long doesn't allow such a
> sequence, to my understanding. Should we extend the API?

For the Maxim, we could argue: "Well, use two separate transactions in
that case." But for the PMBus we are busted in any case.

I do not have the right idea now, but we better change the API soon,
before running into similar backward compatibility issues as before.

I remember a different approach I saw somewhere else, where a list of
transactions was passed to the driver. May be that is more difficult to
use, but would more closely reflect the design of the I2C bus. E.g.

list[0].sla = 0x22;
list[0].txlen = 1;
list[0].txbuf = &reg_num;
list[0].rxlen = 0;
list[0].rxbuf = NULL;

list[1].sla = 0x22;
list[1].txlen = 0;
list[1].txbuf = NULL;
list[1].rxlen = 1;
list[1].rxbuf = &reg_val;

....

list[n].sla = 0x55;

...

NutI2cBusTransact(bus, list, list_len)

If the hardware is able to do this in one transaction, it can be done.
Otherwise the driver must use several start-stop transactions to execute
the list.

Regards,

Harald



More information about the En-Nut-Discussion mailing list