I2C endianess configuration

Hello,

i'm developing a board that comunicates with two i2c sensors. I developed some i2c routines to use with these sensors. Everything works fine (comunication establish and i can exchange data), but i noticed that the sensors need different endianess in transmission: one needs MSBfirst, the other LSBfirst. In general, i could implement an additional step to swap bytes for one of the two devices, but this would require doubling the functions and it should be considered bad practice if some options is available instead.

I believed that the i2c_dt_spec* spec parameter that i need to pass to:

static inline int i2c_write_read_dt(const struct i2c_dt_spec *spec,
				    const void *write_buf, size_t num_write,
				    void *read_buf, size_t num_read)

could contain a flag (i.e. I2C_BIT_ORDER_MSB)or something to specify the endianess of the comunication but i was not able to find anything in both Nrf Connect SDK and Zephyr documentation.

Is there any info i missed? I'm quite confident that there should be a smart solution for this common problem.

Thank you

Francesco

Parents
  • Ok,

    i found out the issues and general infos that can be useful to share.

    To begin with, I2C has a standard MSBfirst communication. Behaving different would be a violation of I2C indication. For this reason, what i said was wrong.

    The confusion came from the fact that the two sensors have 16bit data to read. The first one has LSB data first, MSB data second, the other one is the opposite. This matter regards the memory mapping of the two devices, not I2C. In the end, the result does not change (in one of the two cases bytes need to be swapped), but the concept behind is completely different because I2C don't need a setting on endianness.

    Thank you for your assistance,

    Have a nice developing

    Frax

Reply
  • Ok,

    i found out the issues and general infos that can be useful to share.

    To begin with, I2C has a standard MSBfirst communication. Behaving different would be a violation of I2C indication. For this reason, what i said was wrong.

    The confusion came from the fact that the two sensors have 16bit data to read. The first one has LSB data first, MSB data second, the other one is the opposite. This matter regards the memory mapping of the two devices, not I2C. In the end, the result does not change (in one of the two cases bytes need to be swapped), but the concept behind is completely different because I2C don't need a setting on endianness.

    Thank you for your assistance,

    Have a nice developing

    Frax

Children
No Data
Related