Questions/problems with serial communications
Meepo
Posts: 24
I'm trying to send strings of varying lengths from a Picaxe-08M to a BS2. I'm using bytes, but I could get away with nibbles if it makes the code tighter - I only need to send 16 codes maximum - however, the string of codes could be any length up to 16 bytes (or nibbles). I'm having problem making sense of the incoming serial stream on my BS2...I have no problem sending a known length of bytes, but I need to grab whatever comes down the line regardless of how many bytes there are, and I don't want to waste time sending 16 bytes every time (filling the unused bytes with nulls) if I'm only using a couple of them. Can someone point me to code, algorithms, or advice on how to do this?
Comments
The first thing that came to my mind was the use of the STR formatter . The SERIN instruction uses STR to sequentially place incoming bytes of data into an array , STR has a "switch" that will cause the SERIN instruction to finish and move on if an incoming byte matches the "switch" value.
For example the following will read 16 bytes or fewer if it sees the byte value of 13 (carriage return)
myarray VAR Byte(16)
SERIN rx,baud,[noparse]/noparse]STR myarray \16 \[color=red]13[/color
Jeff T.