diff --git a/cpu/stm32_common/periph/i2c_1.c b/cpu/stm32_common/periph/i2c_1.c index 2422539a8f..61d8347155 100644 --- a/cpu/stm32_common/periph/i2c_1.c +++ b/cpu/stm32_common/periph/i2c_1.c @@ -37,6 +37,7 @@ #include "cpu.h" #include "mutex.h" +#include "byteorder.h" #include "cpu_conf_stm32_common.h" @@ -169,6 +170,10 @@ int i2c_write_regs(i2c_t dev, uint16_t addr, uint16_t reg, if (i2c->ISR & I2C_ISR_BUSY) { return -EAGAIN; } + /* Handle endianess of register if 16 bit */ + if (flags & I2C_REG16) { + reg = htons(reg); /* Make sure register is in big-endian on I2C bus */ + } /* First set ADDR and register with no stop */ /* No RELOAD should be set so repeated start is valid */ int ret = _write(i2c, addr, ®, (flags & I2C_REG16) ? 2 : 1,