I verified this with a modbus slave simulator on the desktop, keeping the same comms and register values and just changing from "Little Endian" (successful reads) to "Big Endian" caused the modbus reads to fail.
Is there a way to change the "Endianness" / Byte Ordering of the communications with the slave device? Barring that, is there another library what works with ESP32 that does support this?
I did find a reference to an attempt in this direction in "esp-idf/components/freemodbus/common/include/esp_modbus_common.h" using macros but it appears these macros are not used anywhere.
Code: Select all
// The Macros below handle the endianness while transfer N byte data into buffer
#define _XFER_4_RD(dst, src) { \
*(uint8_t *)(dst)++ = *(uint8_t*)(src + 1); \
*(uint8_t *)(dst)++ = *(uint8_t*)(src + 0); \
*(uint8_t *)(dst)++ = *(uint8_t*)(src + 3); \
*(uint8_t *)(dst)++ = *(uint8_t*)(src + 2); \
(src) += 4; \
}
#define _XFER_2_RD(dst, src) { \
*(uint8_t *)(dst)++ = *(uint8_t *)(src + 1); \
*(uint8_t *)(dst)++ = *(uint8_t *)(src + 0); \
(src) += 2; \
}
#define _XFER_4_WR(dst, src) { \
*(uint8_t *)(dst + 1) = *(uint8_t *)(src)++; \
*(uint8_t *)(dst + 0) = *(uint8_t *)(src)++; \
*(uint8_t *)(dst + 3) = *(uint8_t *)(src)++; \
*(uint8_t *)(dst + 2) = *(uint8_t *)(src)++ ; \
}
#define _XFER_2_WR(dst, src) { \
*(uint8_t *)(dst + 1) = *(uint8_t *)(src)++; \
*(uint8_t *)(dst + 0) = *(uint8_t *)(src)++; \
}