Hello, I'm developing a DeviceNet application with Silicon Labs C8051F040, Keil compiler and a DeviceNet stack. The problem is the way that Keil stores var (16bit, 32 bit...). When I send data on the DeviceNet, the other devices get the inversion of my data. For example, if i want to send 0x123456, the others Device, such as my computer, receive 0x563412. Is there any way to solve this problem? Please don't tell me to convert the data into 8bit length because that is a very huge work (I'm using the DeviceNet stack of other company). Thanks for reading this topic.
Keil C51 stores multibyte integers in big-endian format. This is the most common network byte order (IP, Ethernet). It is, of course, reversed from the Intel 80x86 format, which means PCs. The PC has more horsepower, and is better equipped to do the byte-swapping. I'd be tempted to define the network byte order as big-endian, and let the PC deal with swapping bytes in the messages that it receives. If you want the source code to be portable between platforms, then you have to do as Andy says, and create a macro or function to do the byte swapping. For some platforms (like the PC), that function actually swaps bytes. For others (the 8051) the macro/function would do nothing.