Forum : 8051
Post Information | Post |
---|---|
May 30, 2011 - 3:34pm
|
Hi, My question is that this code have been working for IAR and other compilers but it doesn’t work with Rkit(80C51) The code is quit simple and to begin with this header file where I declare my struct/union --------------------------------------------------------------------------------------------------------------------------------------------- extern idata union spi_ spi; // declare union extern(must be declared once) Now in my c file I declare #include "data_struct.h" // the file above and everything is working when compiled and linked !. but in my code where I wan’t to split an integer I for instance write it like spi.w = adr;(adr is an unsigned integer ex 0x02E0) On the other hand when assigning spi.b.hi = 0x02 and spi.b.lo = 0xE0 the I see that spi.w = 0xE002(swapped byte) As stated this is working but not here so any suggestions ? Regards |
Hi Claes,
Thanks for your report.
Maybe there is some misunderstanding concerning the byte ordering on different architectures.
On 8051 you have a big endian architecture, meaning that the bytes ordering in memory is "natural": The most significant byte of an object comes first (with the lowest address).
So in your code the lo and hi fields come inverted.
I set up a quick example that works:
The code runs to completion, meaning that all the lines have been properly executed.
If you have further questions on this issue, can you please send us a project that shows the problem?
Best Regards,
Hi,
Well, the main problem remaines even though the swap between hi & lo was explained.
When spi.w = 0x1234 then spi.b.hi = 0x00 and spi.b.lo = 0x00 but if I write directely
spi.b.hi = 0x12 and spi.b.lo = 0x34 then spi.w = 0x1234;
Regards
CKS
Claes,
The example in my reply above clearly shows that assigning values to spi.b.hi and spi.b.lo does work!
In the example we have "spi.b.lo = 0x55;" and "spi.b.hi = 0x66;" which work perfectly so for me there is no problem.
Best Regards,