From b0c05431f7d45f73c1cde5e4dee06efc0104a6b3 Mon Sep 17 00:00:00 2001 From: MrKevinWeiss Date: Fri, 16 Aug 2019 15:04:13 +0200 Subject: [PATCH] cpu/stm32: Fix 16 bit reg endianess for i2c_1 Since i2c_1 i2c_write_regs is cpu specific reg endianess must be swapped there Change reg from little endian to big endian --- cpu/stm32_common/periph/i2c_1.c | 5 +++++ 1 file changed, 5 insertions(+) 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,