I am trying to interface an NXP S32K144 board with an RS-485 based energy meter using Modbus RTU.
The energy meter works correctly with a PC Modbus tool via USB-to-RS485, but I need guidance for implementing and debugging it on the S32K144.
Hi @Turtledove
The S32K144 EVB does not include a native RS-485 transceiver, so you need an external RS-485 PHY (for example MAX3485, SN65HVD series, etc.) between the MCU UART and the energy meter. Connect UART TX/RX from S32K144 to the transceiver DI/RO pins, and connect the transceiver A/B differential pair to the meter A/B lines. DE and \RE can be driven by a GPIO (often tied together for half-duplex Modbus RTU operation).
For software, configure one of the LPUART instances for the meter settings (typically 9600/19200 baud, 8 data bits, no parity or even parity depending on the meter specification, 1 stop bit). Before transmitting a Modbus frame, assert DE, send the frame, wait for transmission complete, then deassert DE and switch back to receive mode. Modbus RTU itself is implemented in software on top of the UART driver.
For debugging, first verify UART traffic with an oscilloscope or logic analyzer. You can also monitor transmitted requests, received responses, CRC status, and decoded register values using watch variables or Real-Time Expressions in S32 Design Studio. Real-Time Expressions can display application variables but cannot directly decode Modbus frames on the bus.
Regards,
Lukas