unsigned long temp = 0x00000000;
How do I access each of the 4 bytes storing 'temp' so I can send them one by one over spi_transfer (which accepts bytes)?
I searched the forums for an answer, but its possible I used the wrong search string!
byte_4 = (temp>>0) & 0xFF;
byte_3 = (temp>>8) & 0xFF;
char byte3,byte2,byte1, byte0;
unsigned long temp;
temp = frequency;
byte3 = (temp>>0) & 0xFF;
byte2 = (temp>>8) & 0xFF;
byte1 = (temp>>16) & 0xFF;
byte0 = (temp>>32) & 0xFF;
Whereas i'm expecting:
Whats wrong with my code?
If you define your bytes as
unsigned char byte3, byte2, byte1, byte0;
you'll get the answer you expect.
(The reason for the behavior you see is that C++ promotes (signed) chars to (signed) ints when calling Serial.println(). 0x97 gets promoted to 0xFFFFFF97.)
Thank you very much, the code works now.