Colway Solutions
Modbus Member Logo

Macro Reference

 

4.3.1       MODBUS_MODE

Macro name

MODBUS_MODE

Description

Controls the Modbus framing type followed by the library.

Permitted Values

MODBUS_TCP

Sets framing type to Modbus TCP

MODBUS_RTU

Sets framing type to Modbus RTU

Remarks

Two framing types are supported by the library - Modbus RTU and Modbus TCP.

 

4.3.2       ENDIAN_STYLE

Macro name

ENDIAN_STYLE

Description

Defines the Endian style of the processor running the library.

Permitted Values

LITTLE_ENDIAN

Processor is of type Little Endian

BIG_ENDIAN

Processor is of type Big Endian

Remarks

Since Modbus is Big Endian, appropriate conversion logic is required when the library is run on a Little Endian processor. The library uses this macro to run such conversion logic conditionally wherever required.

 

4.3.3       RD_BLK_SIZE_BITINFO

Macro name

RD_BLK_SIZE_BITINFO

Description

Fixes the maximum limit to the number of bit status information (both coils and discrete inputs) that may be requested by a Master in one Modbus transaction.

Permitted Values

8 to 2000

 

Remarks

i    A smaller block size limit will enable setting a smaller value for macro TX_BUFFER_SIZE thus reducing the memory used by the library for holding Modbus response packets.

ii    If a Read Coils or Read Discrete Inputs request is received with the number of items set to more than RD_BLK_SIZE_BITINFO, the library responds with an ILLEGAL DATA ADDRESS (0x03) exception code.

 

4.3.4       RD_BLK_SIZE_REGINFO

Macro name

RD_BLK_SIZE_REGINFO

Description

Fixes the maximum limit to the number of register values (both holding registers and input registers) that may be requested by a Master in one Modbus transaction.

Permitted Values

1 to 125

 

Remarks

i    A smaller block size limit will enable setting a smaller value for macro TX_BUFFER_SIZE thus reducing the memory used by the library for holding Modbus response packets.

ii    If a Read Holding Registers or Read Input Registers request is received with the number of items set to more than RD_BLK_SIZE_REGINFO, the library responds with an ILLEGAL DATA ADDRESS (0x03) exception code.

 

4.3.5       WR_BLK_SIZE_BITINFO

Macro name

WR_BLK_SIZE_BITINFO

Description

Fixes the maximum limit to the number of coils that may be written to by a Master in one Modbus transaction.

Permitted Values

8 to 1968

 

Remarks

i    A smaller block size limit will enable setting a smaller value for macro TX_BUFFER_SIZE thus reducing the memory used by the library for holding Modbus request packets.

ii    If a Write Multiple Coils request is received with the number of items set to more than WR_BLK_SIZE_BITINFO, the library responds with an ILLEGAL DATA ADDRESS (0x03) exception code.

 

4.3.6       WR_BLK_SIZE_REGINFO

Macro name

WR_BLK_SIZE_REGINFO

Description

Fixes the maximum limit to the number of holding registers that may be written to by a Master in one Modbus transaction. A smaller block size limit will enable setting a smaller value for macro RX_BUFFER_SIZE thus reducing the memory used by the library for holding Modbus request packets.

Permitted Values

1 to 123

 

Remarks

i    A smaller block size limit will enable setting a smaller value for macro TX_BUFFER_SIZE thus reducing the memory used by the library for holding Modbus request packets.

ii    If a Write Multiple Registers request is received with the number of items set to more than WR_BLK_SIZE_REGINFO, the library responds with an ILLEGAL DATA ADDRESS (0x03) exception code.

 

4.3.7       RX_BUFFER_SIZE and TX_BUFFER_SIZE

Macro name

RX_BUFFER_SIZE

TX_BUFFER_SIZE

Description

These macros control the sizes of receive and transmit buffers that the library allocates for receiving Modbus requests and sending responses.

Permitted Values

7 - 256

Modbus RTU

11 - 260

Modbus TCP

Remarks

i    RX_BUFFER_SIZE must be set large enough for the library to support the block size limits specified by WR_BLK_SIZE_BITINFO and WR_BLK_SIZE_REGINFO.

ii    TX_BUFFER_SIZE must be set large enough for the library to support the block size limits specified by RD_BLK_SIZE_BITINFO and RD_BLK_SIZE_REGINFO.

iii    The recommended way to set these macros is by using the MMPL configurator which automatically calculates the values for the buffers based on the values set for the block size limiting macros.

in    If these macros are manually set, ensure that the buffers are large enough to hold the MBAP header (Modbus TCP only) or the Slave/Server Address (Modbus RTU only), the Modbus PDU and the CRC bytes (Modbus RTU only)

 

4.3.8  STDIO_SUPPORTED

Macro name

STDIO_SUPPORTED

Description

Indicates to the library if the platform supports formatted I/O or not.

Permitted Values

1

Formatted I/O supported

0

Formatted I/O not supported

Remarks

i    This macro is used by the library when creating debug messages.

ii    If the value for this macro is 1, the library formats debug messages with relevant numerical information by using sprint formatted I/O function. If not, the debug messages are plain textual information only.

 

4.3.9  DEBUG_LEVEL

Macro name

DEBUG_LEVEL

Description

This macro is used to enable or disable output of debugging messages by the library and to set the type of instances for which a debug message is generated.

Permitted Values

DEBUG_NONE

Debug message generation is disabled.

DEBUG_ERROR

Debug messages are generated only when error conditions occur in the library execution.

DEBUG_WARNING

Debug messages are generated only when error conditions or such other conditions occur in the library execution that could lead to potential error conditions.

DEBUG_INFORMATION

In addition to generating debug messages under error and warning conditions messages are generated that provide a general status indication of the execution of the stack.

DEBUG_VERBOSE

This setting is a superset of the above three settings. In addition to debug messages for all the above conditions, extensive messages are printed out with as much information for the user as would be required for deep debugging.

Remarks

i    As the debug level increases from DEBUG_NONE to DEBUG_VERBOSE, the code memory occupied by the library as well as the CPU utilisation by it increase.

ii    It is recommended to set the level to DEBUG_ERROR in the release version of your product. This will help catch errors in the field.

 

4.3.10  CRC_TABLE_LOCATION

Macro name

CRC_TABLE_LOCATION

Description

This macro is used to control the manner in which the CRC tables are created and stored in the library thereby optimising the use of code and data memory.

Permitted Values

IN_RAM

CRC tables are created once at the start of the program and stored in data memory (RAM).

IN_ROM

CRC tables are stored in code memory (ROM) as a const array.

Remarks

i    This macro is used only in MODBUS RTU mode.

ii    The CREATE_DYNAMIC setting saves both data and code memory at the cost of lower performance during runtime since the CRC tables have to be created for every Modbus packet received.

iii    The IN_RAM setting saves ROM (code memory) at the cost of using more data memory. Access to the CRC tables could be faster since RAM access is faster than ROM access.

in    The IN_ROM setting saves RAM (data memory) at the cost of using more code memory.

 

4.3.11  CRC_TABLE_LOC_MODIFIER

Macro name

CRC_TABLE_LOC_MODIFIER

Description

This macro is used to set the keyword that will cause variables in code memory (ROM) or RAM.

Permitted Values

static xdata

Set value such that the table goes into RAM.

code

Set value such that the table goes into ROM/Flash.

Remarks

i    Many compilers by default may store constant variables in code memory. If so, set this macro to a blank.

 

4.3.12  xdata

Macro name

xdata

Description

This macro is used to set the keyword that will cause variables to be placed in external memory.

Permitted Values

The keyword used for forcing constant variables into code memory. E.g. the keyword 'xdata'

Remarks

i    Microcontrollers have internal RAM (sometimes in the form of on-chip registers) and external RAM (also on-chip but not a part of the MCU core). This keyword is used to force program variables to be placed in the external RAM.

ii    The location of program variables also depends on the memory model of setting of the compiler. For instance a large memory model could by default place all program variables in external ram in which case this macro setting becomes irrelevant.

iii    The library uses this macro to modify the location of transmit buffer and the receive buffer since they form the major component of memory usage by the library. All other variables used in the library are placed in the default memory type defined by the memory model setting.

 

Back to Index

Privacy Policy Site Map FAQ Contact Us