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

I'm trying to send MP3 data from Euphoria 3.1 program through a USB cable/port to an Arduino Uno running a program("sketch") that is, I think, written in a variant of C plus plus.

I had things beginning to work, thanks to Fernando, & ryanj, but I was testing it with text files, using something like the protocol ryanj suggested, and code suggestions from Fernando, and then realized that MP3 files could contain data which looks like header protocol control codes, so to eliminate that potential problem, I am now trying to instead use length of data info in header to read data on the Uno.

And a suggestion I got from the Arduino side involves using 'structures' (which is another thing I'm not familiar with), which include 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.)

new topic     » topic index » view message » categorize

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

DanM_anew said...

... 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.

new topic     » goto parent     » topic index » view message » categorize

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

DerekParnell said...

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.

Thanks Derek, makes sense! I think I'd need {#A,#5,#A,#5} to yield the expected 4 byte 0xA5A5 ?

new topic     » goto parent     » topic index » view message » categorize

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

DanM_anew said...

I think I'd need {#A,#5,#A,#5} to yield the expected 4 byte 0xA5A5 ?

Ummm ... 0xA5A5 is still a 2-byte value. Do you mean 0x0A050A05 ?

new topic     » goto parent     » topic index » view message » categorize

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

DerekParnell said...
DanM_anew said...

I think I'd need {#A,#5,#A,#5} to yield the expected 4 byte 0xA5A5 ?

Ummm ... 0xA5A5 is still a 2-byte value. Do you mean 0x0A050A05 ?

Um, I'm not sure, the structure suggested for the Arduino program said, "uint32_t syncPattern; / /4 bytes with a fixed value, e.g. 0xa5a5, marks the beginning of a header", so I'm not sure at this time. I'll have to find out more from the Arduino side.

new topic     » goto parent     » topic index » view message » categorize

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

DanM_anew said...

... the structure suggested for the Arduino program said,

"uint32_t  syncPattern;   / /4 bytes with a fixed value, e.g. 0xa5a5, marks the beginning of a header", 

Ok, so we still have two options, depending on if its a big-endian or little-endian CPU.

The two equivalent byte streams in Euphoria would be ...

constant sync_BE = {#00, #00, #A5, #A5} 
constant sync_LE = {#A5, #A5, #00, #00}  -- Typically Intel machines. 
new topic     » goto parent     » topic index » view message » categorize

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

DerekParnell said...
DanM_anew said...

... the structure suggested for the Arduino program said,

"uint32_t  syncPattern;   / /4 bytes with a fixed value, e.g. 0xa5a5, marks the beginning of a header", 

Ok, so we still have two options, depending on if its a big-endian or little-endian CPU.

The two equivalent byte streams in Euphoria would be ...

constant sync_BE = {#00, #00, #A5, #A5} 
constant sync_LE = {#A5, #A5, #00, #00}  -- Typically Intel machines. 

Thanks Derek, I find things that say it's little-endian, but I'll have to test it, as I don't understand why you have the #00 pairs following the #A5 pairs rather than interspersed:

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

And thanks for subtly reminding me to put all code in code format, I see that it does help, even for non Eu code!

new topic     » goto parent     » topic index » view message » categorize

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

DerekParnell said...
DanM_anew said...

... the structure suggested for the Arduino program said,

"uint32_t  syncPattern;   / /4 bytes with a fixed value, e.g. 0xa5a5, marks the beginning of a header", 

Ok, so we still have two options, depending on if its a big-endian or little-endian CPU.

The two equivalent byte streams in Euphoria would be ...

constant sync_BE = {#00, #00, #A5, #A5} 
constant sync_LE = {#A5, #A5, #00, #00}  -- Typically Intel machines. 

Well I'll be! Your little-endian WORKS! I truly don't understand why it should be

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

rather than

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

but right now I don't CARE! It works, that's good enough for me to proceed from!

THANK YOU DEREK!

new topic     » goto parent     » topic index » view message » categorize

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

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).

new topic     » goto parent     » topic index » view message » categorize

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

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 message » categorize

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

Turns out I was wrongly informed as well as forgetting how hex numbers were formed: the 4 8-bit bytes were actually supposed to be 0xa5a5a5a5! Which sent perfectly well as: sync = {#A5, #A5, #A5, #A5}

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu