PDA

View Full Version : Beginner SERIN question: STR v. Arrays



Professor Chaos
11-19-2006, 09:52 AM
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:



Array VAR BYTE(3)

DO
SERIN 0,16468, [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, [Array(0),Array(1),Array(2)]



or



SERIN 0,16468, [Array(0)]
SERIN 0,16468, [Array(1)]
SERIN 0,16468, [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!

Chris Savage
11-20-2006, 01:30 AM
Professor,

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