Re: [3.1]How serial send 0xa5a5 so correctly received & tested in 4byte structure?[SOLVED]

new topic     » goto parent     » topic index » view thread      » older message » newer message
DerekParnell said...
DanM_anew said...

... I don't understand why you have the #00 pairs following the #A5 pairs rather than interspersed:

constant sync_LE = {#A5, #00, #A5 ,#00}  

The simple answer is that that would be a different number.

  1. A5A5 is the number 42405 in decimal. It takes up a minimum of 2 bytes of RAM (16-bits). The exact amount of RAM depends on how its defined in a program. In the example you gave it was declared as an unsigned 32-bit integer, and thus it gets padded with two bytes of leading zeros to make up the full 32 bits. In a big-endian system, the byte layout of a 32-bit number has the most significant bytes first, thus it would be in RAM as #00 #00 #A5 #A5. In little-endian systems the least significant bytes come first in RAM, so it would look like #A5 #A5 #00 #00.

The {#A5, #00, #A5 ,#00} either repesents the number #00A500A5 or 10813605 (little-endian), or #A500A500 or 2768282880 (big-endian).

Thanks for the explanation! I said I didn't care why, but I see now that I do. It's funny, I even had some of that, I had seen the decimal value of the hex number #A5A5, but hadn't grasped, even after you mentioned it, that it took minimum 16 bits. I'd even seen that it's 1010010110100101 in binary, which should have clued me in: 1010 0101 1010 0101. I was totally forgetting how hex numbers were formed! I looked at the #A, and foolishly thought, "one character, one byte", so #A5A5 should give the required 4 bytes! Now I understand why the zeros were needed to get 4 8-bit bytes = 32.

And of course, the fact that it worked is pretty important too! I couldn't yet make debug statements easily pass back from the Uno from the sync test to EuTerminal, so I just made the sync test turn on a led on the Uno if what I sent to it from EuTerminal matched the value present & expected in the Uno program.

You answer questions very well Derek, thank you!

Dan M.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu