Colway Solutions
Modbus Member Logo

Set Endian Architecture


Modbus follows the Big Endian byte ordering system. Therefore the byte ordering has to be reversed if the Modbus library is deployed on a Little Endian processor. The library has a macro ENDIAN_STYLE, used to set the correct Endian characteristic.



a)   Open file MMPL_UserIf.h

b)   Locate the definition of macro ENDIAN_STYLE

c)    If your platform is Little Endian, change the above macro's value to LITTLE_ENDIAN. If it is Big Endian, change the macro's value to BIG_ENDIAN. The modified line should look like this:

#define ENDIAN_STYLE LITTLE_ENDIAN/* for Little Endian */

#define ENDIAN_STYLE BIG_ENDIAN/* for Big Endian */

d)   Rebuild your project and test.



  • The utility functions provided by the Formatter (e.g. MMPL_ShortIntsToBuffer) are "Endian-aware" - they are programmed check and ensure that transfers from
    interpreted data types to raw buffers conform to Endianess of the platform.

  • If you use your own code for such transfers, remember to address the issue of Endianess. Raw data in a Modbus packet is always in Big Endian format.

  • To know the Endianess of your platform, refer to the User Manual of your processor.

  • If you are unsure of the Endianess of your platform, a simple technique to determine this is to create a 'C' program with an unsigned short int variable (16-bit)
    and store the value 0xABCD in it:


    unsigned short int testVar = 0xABCD;


    Then debug this program and see the memory contents (using a Memory Dump or Memory Watch window) at the location of this variable. If you find 0xAB stored first and then 0xCD, you have a Big Endian system, else you have a Small Endian system.


    Back to Index

    Privacy Policy Site Map FAQ Contact Us