Re: [3.1]How serial send 0xa5a5 so correctly received & tested in 4byte structure?
- Posted by DerekParnell (admin) Apr 08, 2014
- 2206 views
... a 'sync' pattern to begin the header, eg. 0xa5a5, which in the suggested structure is:
**uint32_t syncPattern; //4 bytes with a fixed value**However, when I try to send that hex value, with sync = #A5A5, like this:
serial_puts(hCom1, sync & justFileName & lengthDATA & chkSUM & dataChunk)
I get an echo return from the Uno of 165, which is just the first #A5 portion of #A5A5. (And immediately following that is the actual data sent from the test file.)
What should I do to correctly send #A5A5 (0xa5a5) ? (So that it is received as the 4 bytes the Uno 'sketch' (program) structure expects.)
Firstly, #A5A5 is only two bytes long. Each #A5 is just one byte long.
Secondly, the serial_puts() routine only sends the lower (least significant) 8-bits (a byte) from each element in the sequence. This means that if the first element is #A5A5, it only sends the rightmost #A5 byte. To fix this, change the definition of 'sync' to ...
constant sync = {#A5, #A5} -- a TWO byte header sync marker.
If you need a FOUR byte marker then use {#A5,#A5,#A5,#A5} maybe.

