S
I am programming an ATmega 644p microcontroller which will be part (slave) of a master-slave sensor network over RS485. We decided to use modbus for protocol.
Two master applications are in developement and they asked me about the interface (registers and definition of corresponding values). Since I'm new to modbus, I'm unsure about how to define them.
First possibility might be a linear memory layout (first 32 bit data in HR 0000, second in HR 0002, ...). Since I do not yet know about the max data length of many variables this could cause severe limitations in the future. There would have to be zero-filled 'reserve registers' after each data.
Second possibility might be to take each register as a pointer or index to data-items of variable length (first 32 bit data referenced by HR 0000, second by HR 0001, ...). The data would still be read or written in units of words using functions 0x03 and 0x10, only it would be impossible to read several variables in one go.
On the other hand, accessing several variables at once would be impossible anyway because some variables do not even exist in memory but are computed after requested.
In general, I want the device to work with most existing applications and equipement and to keep it as close to the standard as possible but still simple and easy to adapt to future changes.
So, should I stick to the former or latter solution or do it completely different?
Many thanks and kind regards,
Sebastian Seidel
(eMail: seidel [at] seika.de)
PS:
Apart from the register mapping, I thought of the following layout:
- All four tables overlap, R and RW data mixes.
- Functions 0x03 and 0x10 used for data access.
- Floats transfered big-endian.
- Strings transfered like they would be read.
- Data saved in native (little endian) format and shuffled before sending.
- Multibyte data accessed by specifying its first register. Otherwise, exception code 0x02 returned (for example when trying to read the second part of a 32 bit value).
Two master applications are in developement and they asked me about the interface (registers and definition of corresponding values). Since I'm new to modbus, I'm unsure about how to define them.
First possibility might be a linear memory layout (first 32 bit data in HR 0000, second in HR 0002, ...). Since I do not yet know about the max data length of many variables this could cause severe limitations in the future. There would have to be zero-filled 'reserve registers' after each data.
Second possibility might be to take each register as a pointer or index to data-items of variable length (first 32 bit data referenced by HR 0000, second by HR 0001, ...). The data would still be read or written in units of words using functions 0x03 and 0x10, only it would be impossible to read several variables in one go.
On the other hand, accessing several variables at once would be impossible anyway because some variables do not even exist in memory but are computed after requested.
In general, I want the device to work with most existing applications and equipement and to keep it as close to the standard as possible but still simple and easy to adapt to future changes.
So, should I stick to the former or latter solution or do it completely different?
Many thanks and kind regards,
Sebastian Seidel
(eMail: seidel [at] seika.de)
PS:
Apart from the register mapping, I thought of the following layout:
- All four tables overlap, R and RW data mixes.
- Functions 0x03 and 0x10 used for data access.
- Floats transfered big-endian.
- Strings transfered like they would be read.
- Data saved in native (little endian) format and shuffled before sending.
- Multibyte data accessed by specifying its first register. Otherwise, exception code 0x02 returned (for example when trying to read the second part of a 32 bit value).