PDA

View Full Version : Ignore data



philipad23
04-25-2006, 04:12 AM
Hi everyone

I have an RF receiver connected in serial with the BS2 and I use it to send a word size dara (16bit). Is there a way for the BS2 to ignore the data in the case of lost bits in the transmission, which means that the data received is less than 16 bits ?

Thanks

philipad23
04-25-2006, 04:13 AM
I mean to send data with a transmitter to the receiver :)

Chris Savage
04-25-2006, 08:30 AM
You cannot send the data 16 bits at a time.ˇ You must break a WORD variable up into two BYTE sized variables in order to send serially.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com (mailto:csavage@parallax.com)

philipad23
04-25-2006, 10:30 AM
ok..how can I ignore the data in the case of lost bits?

Chris Savage
04-25-2006, 11:08 AM
I'm not sure, because you have posted no code, and your post indicates you're not sure how the data is being transmitted.ˇ Please post your code.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com (mailto:csavage@parallax.com)

philipad23
04-28-2006, 01:34 PM
my code consists of a simple SERIN instruction

a VAR Word

main:
SERIN 0, 16780,5000, Timeout, [DEC a]
DEBUG ?a
GOTO main

timeout:
DEBUG "timeout"
RETURN

If I send a signal with BS1 which is connected directly to a BS2' pin, I get the signal (for example the number 65535). Through RF communication between BS1 and BS2 on the DEBUG I get 535, 5535 and rarely 65535. What I want is the 535 or 5535 to be disregarded.

Bruce Bates
04-28-2006, 04:50 PM
Philip -

Asynchronous serial data transmission is a byte-oriented protocol, so you will need to read the data in as bytes, regardless of what you want to do with it later on down the line. Here is your program changed to accomodate byte input, then stored it in a WORD sized variable:

/code
a VAR Word

main:
'ˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇ 8 bits onlyˇˇˇ 8 bits only
SERIN 0, 16780,5000, Timeout, [a.highbyte,ˇˇ a.lowbyte]

DEBUG ?a.highbyte 'Display just the top end

GOTO main

timeout:

DEBUG "timed out"
GOTO main
END

code/

If that's not exactly what you were looking to do, you may need to use the SHIFT function to dump the bits you want to eliminate:
a = a >> 8 'Dump 8 low bits into the bit-bucket near the Black Hole at the right
a = a << 8 'Re-align the data back to where it was

Regards,

Bruce Bates

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->

Chris Savage
04-28-2006, 09:15 PM
To add to what Bruce said if you're getting a lot of errors in your transmission you can try reducing the baud rate or you can implement CRC (Cyclic Redundancy Checksum) which will add a little overhead to your transmission, but will ensure the received data is accurate.ˇ This would involve sending the CRC byte after the packet of digits.ˇ If the CRC doesn't match on the receiving side then you discard that packet.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com (mailto:csavage@parallax.com)

philipad23
04-29-2006, 09:21 AM
I am aware that the signal must be byte sized but my code works anyway...
I will try to reduce the baud rate and to separate the the word into bytes, but the thing is that sending a synchronization byte I can get the signal as appropriate.

SEROUT 0, 16780, [126,("A"),DEC a] 'transmitter

SERIN 0, 16780,5000, Timeout, [WAIT ("A"),DEC a] 'receiver

The problem is that as the instruction waits for synchronization, it never times out. Is there a way to make it to time out or this is not supported by BS2?

PJ Allen
04-29-2006, 09:52 AM
philipad23 said...
SERIN 0, 16780,5000, Timeout, [WAIT ("A"),DEC a] 'receiver
The problem is that as the instruction waits for synchronization, it never times out. Is there a way to make it to time out or this is not supported by BS2?
You can't make it to "timeout" away from a WAIT once you tell it to WAIT, that is a WAIT indefinitely (forever, if necessary.)ˇ It'll bail out if there's no valid data in 5 seconds beforehand, as written, but past that it's going to stay in WAIT till it gets satisfied ("A".)ˇ