microcontroller - Byte order issue between Micro controller and Microprocessor? -
my host stm32l100 "little enidian"which connected network processor lon:ft5000 "big enidian",communicates through uart ,how on come problem of difference in enidians.,one solution know,interchange bits before sending , receiving,any standard solution , app involves nested structure , enums)
the network protocol should define endianness. example, tcp/ip , modbus big endian. while cip protocols such devicenet little endian. if you're creating own protocol choose whichever endianness convenient.
the software running on network endpoints should convert data appropriately. note means swapping bytes rather swapping bits.
see introduction endianness more information including excerpt.
a common solution endianness problem associated networking define set of 4 preprocessor macros shown in listing 1. these macros follows:
htons(): reorder bytes of 16-bit unsigned value processor order network order. macro name can read "host network short."
htonl(): reorder bytes of 32-bit unsigned value processor order network order. macro name can read "host network long."
ntohs(): reorder bytes of 16-bit unsigned value network order processor order. macro name can read "network host short."
ntohl(): reorder bytes of 32-bit unsigned value network order processor order. macro name can read "network host long."
Comments
Post a Comment