modbus/README.md
2024-10-11 17:33:25 +02:00

37 lines
1.8 KiB
Markdown

# Modbus slave RTU library
Simple implementation of Modbus RTU. *(Does NOT support ASCII and TCP)*.
## Usage
1. Implement functions modbus\_callback\_function() and modbus\_uart\_transmit\_function()
* modbus\_uart\_transmit\_function() sends data via UART
* modbus\_callback\_function() does the real work: read sensors, set outputs...
note that when filling buffers (e.g. input\_registers[]) user must ensure that all data is big-endian. These functions are implementation-specific.
2. Set device address (variable modbus\_device\_address); you can do this either
* setting modbus\_device\_address directly (modbus.h needs to be included, duh)
* using modbus\_set\_device\_address(uint8\_t address) function
Or you can leave address as-is (MODBUS\_DEFAULT\_SLAVE\_ADDRESS) and set it via Modbus during runtime
3. Call modbus\_process\_msg() after message reception; you need to observe Modbus RTU timing:
* pauses between chars in frame are less or equal to 1.5 char
* pauses between frames are at least 3.5 chars (of silence)
For more information see section 2.5.1.1 (MODBUS Message RTU Framing) in "MODBUS over Serial Line: Specification and Implementation Guide"
Note that byte order is big endian.
## Useful links:
* [Picotech article](https://www.picotech.com/library/oscilloscopes/modbus-serial-protocol-decoding)
* [IPC2U article](https://ipc2u.com/articles/knowledge-base/modbus-rtu-made-simple-with-detailed-descriptions-and-examples/)
* [Modbus documentation: modbus over serial line](https://modbus.org/docs/Modbus_over_serial_line_V1_02.pdf)
* [Modbus documentation: modbus application protocol](https://www.modbus.org/docs/Modbus_Application_Protocol_V1_1b.pdf)
## License
This project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for details.