I want to use a struct to exchange data between two µC using nRF24L01+, not sure if this matters. I've defined the same struct on both µC which uses 11 bytes
I receive the following data (for-loop printing each byte of the struct):0x1 0x2 0x3 0x4 0 0x5 0 0x6 0 0 0As you can see "0x4 0", "0x5 0" and "0x6 0 0 0" are myData.val, myData.sendrequest and myData.counter, respectively, but with bytes in wrong order. What am I missing here? Maybe it has something to do with the nRF24L01+ modules' sending routine, maybe it's simply my lack of experience using C?
Thanks, that is great news Ok, ATTiny13A uses little-endian but Raspbian uses little-endian too, as far as my search revealed. I also ran a test that states my Raspbian uses little-endian.
Now I'm lost.
Why is the order still wrong when I use?
Strange question in what regard? Well, sorry, I thought the forum "Programming Questions - Understanding the language, error messages, etc." would be suitable. First time using structs with Arduino IDE.
The data was transmitted correctly, as can be seen in the for-loop output. Only accessing the struct data seems to be a problem.
terraduino:
Strange question in what regard? Well, sorry, I thought the forum "Programming Questions - Understanding the language, error messages, etc." would be suitable. First time using structs with Arduino IDE.
There is no aligning/padding of simple structure members for 8 Bit Arduinos, but it seems to be different on the Raspi.
Thanks again, Whandall! attribute((packed)) in the receiver code did the trick.
I'm sure I'll find the explanation in the link you provided. Of course I'm curious to understand why the observed behavior occurred and what other mechanisms may cross my way.