Beginner SERIN question: STR v. Arrays
Hi all -
I'm just starting out with the BS2 and am wondering about serial behavior. I am reading input from a serial device that communicates with 3-byte commands at 9600 baud. If I read the input according to the following:
I display the expected data. However, if I use:
or
to read the input, I get the first byte correct, but the second two bytes are wrong. The second example gives different wrong bytes than the third example.
Is this just a timing issue, or am I missing something fundamental about how arrays or SERIN work?
Thanks!
I'm just starting out with the BS2 and am wondering about serial behavior. I am reading input from a serial device that communicates with 3-byte commands at 9600 baud. If I read the input according to the following:
Array VAR BYTE(3) DO SERIN 0,16468, [noparse][[/noparse]STR Array \3] 'Wait for 3 bytes on Pin 0 DEBUG BIN8 Array(0), " ",BIN8 Array(1)," ",BIN8 Array(2), CR 'Display the bytes in binary format LOOP
I display the expected data. However, if I use:
SERIN 0,16468, [noparse][[/noparse]Array(0),Array(1),Array(2)]
or
SERIN 0,16468, [noparse][[/noparse]Array(0)] SERIN 0,16468, [noparse][[/noparse]Array(1)] SERIN 0,16468, [noparse][[/noparse]Array(2)]
to read the input, I get the first byte correct, but the second two bytes are wrong. The second example gives different wrong bytes than the third example.
Is this just a timing issue, or am I missing something fundamental about how arrays or SERIN work?
Thanks!
Comments
·
·· You are correct….It is a timing issue.· At 9600 bps you are kind of at the threshold of the BS2 ability to get multiple bytes without flow control since there is no FIFO buffer.· The STR modifier allows the SERIN command to more efficiently drop incoming bytes into an array than inputting individual bytes in different variables.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support