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.
"a simple solution might be a union"
A union is not a solution in itself; it is just a way to get at the individual bytes of multi-byte objects.
In your transmit routines, you also need code to send these individual bytes in the correct order - this is the function of htons();
In your receive routines, you also need code to put the indiviadual received bytes into the correct locations in the union - this is the function of ntohs().
And you probably also want some conditional-compilation to ensure that you automatically use the right ones!