descriptionSure-Board as Modbus RTU device (ATmega16)
ownerManfred Steiner
last changeSat, 14. Dec 2024, 08:07:09

Infos on markdown to HTML conversion

  1. started as process 2667809: /usr/bin/pandoc -f gfm -t html5 --highlight-style pygments

Sure Board as Modbus RTU Device

API

See also: sure_modbusslave/released/readme

Version: V1.6(10) (Jan 9 2014 07:59:39) Hex-File: https://www.htl-mechatronik.at/gitweb/public/sx/?p=modbus-sure.git;a=blob;f=sure_modbusslave/released/sure.elf.hex

Serial interface: 57600 Bit/s, 8N2 Subversion revision: 22 Committed by: SX Implementation remarks: none Deviation from Modbus protocol MODBUS over serial line specification and implementation guide V1.02 2.5.1.1 MODBUS message RTU framing: T1.5 = 2.8ms instead of 287us (11/576001.5=287us) T3.5 = 6.8ms instead of 668us (11/576003.5=668us)


Read coils (0x01): 4 LEDs PA0, PA1, PA2 and PA3 Address 0..3, Quantity 1..4 Address 0: LED PA0 (1=LED on, 0=LED off) Address 1: LED PA1 (1=LED on, 0=LED off) Address 2: LED PA2 (1=LED on, 0=LED off) Address 3: LED PA3 (1=LED on, 0=LED off)


Read discrete inputs (0x02): push buttons SW1 and SW2 Address 0..1, Quantity 1..2 Address 0: SW1 (0=not pressed, 1=pressed) Address 1: SW1 (0=not pressed, 1=pressed)


Read holding registers (0x03): read back registers for controlling the 7-segment display Address: 0..4 Address 0: last written value to hold register addresss 0, 1 or 2 Address 1: last written value to hold register addresss 0, 1 or 2 Address 2: last written value to hold register addresss 0, 1 or 2 Address 3: 7-segement code for digit 3 and 2 (high byte, low byte) Address 4: 7-segement code for digit 1 and 0 (high byte, low byte)

7-segment code: 0x80->point, 0x01->led a, 0x02->led b, ... 0x40->led g


Read input register (0x04): Atmega I/O register, temperature sensor, version string Address: 0..0x3f, 0xfff0..0xffff Address 0x00 .. 0x2f -> Atmega16 I/O registers (two 8 bit registers combined to 16 bit) example 1: Atmega I/O register TCNT1 on $4c -> modbus address 0x26 example 2: Atmega I/O register PINC on $33 -> high byte of modbus address 0x19

Address 0x30 .. 0x33 -> LM75A registers  (value 0x7fff -> unvalid)
                        modbus address 0x30: value/256 -> temperature in celsius degree (two's complement)

Address 0xfff0..0xffff -> version string of this software -> "V1.6(10) (Jan  9 2014 07:59:39)"

Write single coil (0x05) Address: 0..3, value: 0x0000 or 0xff00 Address 0: LED PA0 (0xff00=LED on, 0x0000=LED off) Address 1: LED PA1 (0xff00=LED on, 0x0000=LED off) Address 2: LED PA2 (0xff00=LED on, 0x0000=LED off) Address 3: LED PA3 (0xff00=LED on, 0x0000=LED off)


Write single (hold) register (0x06): set values on 7-segment display Address: 0..4 Address 0: 7-segment set value and show in hex format ("0000" .. "FFFF") Address 1: 7-segment set value and show in unsigned decimal format " 0" .. "9999") Address 2: 7-segment set Value and show in signed decimal format ("-999" .. "9999") Address 3: 7-segement set digit 3 and 2 (value high byte, value low byte) Address 4: 7-segement set digit 1 and 0 (value high byte, value low byte)


Write multiple coils (0x0f): set one or more LEDs (one bit in value for one LED) Address: 0..3, Quantity 1..4 (address+quantity<=4) Address 0: LED PA0 (1=LED on, 0=LED off) Address 1: LED PA1 (1=LED on, 0=LED off) Address 2: LED PA2 (1=LED on, 0=LED off) Address 3: LED PA3 (1=LED on, 0=LED off)


Write multiple (hold) registers (0x10): set values on 7-segment display Address: 0..4 Address 0: 7-segment set value and show in hex format ("0000" .. "FFFF") Address 1: 7-segment set value and show in unsigned decimal format " 0" .. "9999") Address 2: 7-segment set Value and show in signed decimal format ("-999" .. "9999") Address 3: 7-segement set digit 3 and 2 (value high byte, value low byte) Address 4: 7-segement set digit 1 and 0 (value high byte, value low byte)


Examples:

Modbus function code 0x01 (Read coil)

request: 02 01 00 00 00 04 3d fa response: 02 01 01 00 51 cc

Modbus function code 0x02 (Read discrete Input)

request: 02 02 00 00 00 01 b9 f9 response: 02 02 01 00 a1 cc

Modbus function code 0x03 (Read holding register)

request: 02 03 00 00 00 05 85 fa response: 02 03 0a 00 00 00 00 00 00 00 00 00 00 ff ff ff ff ff ff ff ff ff ff 3b be

Modbus function code 0x04 (Read input register) example 1: read temperature from LM75A

request: 02 04 00 30 00 01 31 f6 response: 02 04 02 17 40 00 00 44 e4

Modbus function code 0x04 (Read input register) example 2: read version string

request: 02 04 ff f0 00 10 c1 d2 response: 02 04 20 56 31 2e 36 28 31 30 29 20 28 4a 61 6e 20 20 39 20 32 30 31 34 20 30 37 3a 35 39 3a 33 39 29 00 00 a0 02 9e 00 00 80 00 00 1f 1f 00 ff f0 00 20 00 08 00 08 00 00 ff 00 00 0c 04 1e 04 1e 00 1e 73 47 response as string: V1.6(10) (Jan 9 2014 07:59:39)

Modbus function code 0x05 (Write single coil)

request: 02 05 00 02 ff 00 2d c9 response: 02 05 00 02 ff 00 2d c9

Modbus function code 0x06 (Write single (hold) register)

request: 02 06 00 02 00 0a a8 3e response: 02 06 00 02 00 0a a8 3e

Modbus function code 0x0f (Write multiple coils)

request: 02 0f 00 00 00 04 01 06 fe 81 response: 02 0f 04 00 00 00 04 c8 3c

Modbus function code 0x10 (Write multiple (hold) registers)

request: 02 10 00 01 00 02 04 ff ff ff ff 3c b3 response: 02 10 04 00 01 00 02 1b 91