My program errors when trying to send RS232 data from a BS2 to a BS2sx
wmtell1
Posts: 14
My application has two Stamps talkingto to each other using RS232. I'm trying to take advantage of the higher speed on the BS2sx by setting the baud rate on the BS2sx to 9600 and the BS2 to 192000 but I'm seeing errors every time. I'm using the DEBUG window to view the data that is sent and received. Does anyone hav a clue as to what is happening?
I've listed the relevant sample code below.
' {$STAMP BS2}
' {$PBASIC 2.5}
'BS2 send RS232
'
[noparse][[/noparse] Constants ]
RX2········ CON 0 ' receive (from BS2sx)
TX2········ CON 1 ' transmit (to BS2sx)
'
[noparse][[/noparse] Variables ]
sData VAR Word
'
[noparse][[/noparse] Main ]
'Baud rate for BS2 = 19200
sData=2000
SEROUT TX2,16416,[noparse][[/noparse]DEC5 sData]
DEBUG "sData = ",DEC5 sData
END
' {$STAMP BS2sx}
' {$PBASIC 2.5}
'BS2sx receive RS232
'
[noparse][[/noparse] Constants ]
RX2sx········ CON 0 ' receive (from BS2)
TX2sx········ CON 1 ' transmit (to BS2)
'
[noparse][[/noparse] Variables ]
rData VAR Word
'
[noparse][[/noparse] Main ]
'Baud rate for BS2sx = 9600
'DEBUG "sData = ",DEC5 sData
SERIN RX2sx,16468,[noparse][[/noparse]DEC5 rData]
DEBUG "rData = ",DEC5 rData
END
Thanks,
William
I've listed the relevant sample code below.
' {$STAMP BS2}
' {$PBASIC 2.5}
'BS2 send RS232
'
[noparse][[/noparse] Constants ]
RX2········ CON 0 ' receive (from BS2sx)
TX2········ CON 1 ' transmit (to BS2sx)
'
[noparse][[/noparse] Variables ]
sData VAR Word
'
[noparse][[/noparse] Main ]
'Baud rate for BS2 = 19200
sData=2000
SEROUT TX2,16416,[noparse][[/noparse]DEC5 sData]
DEBUG "sData = ",DEC5 sData
END
' {$STAMP BS2sx}
' {$PBASIC 2.5}
'BS2sx receive RS232
'
[noparse][[/noparse] Constants ]
RX2sx········ CON 0 ' receive (from BS2)
TX2sx········ CON 1 ' transmit (to BS2)
'
[noparse][[/noparse] Variables ]
rData VAR Word
'
[noparse][[/noparse] Main ]
'Baud rate for BS2sx = 9600
'DEBUG "sData = ",DEC5 sData
SERIN RX2sx,16468,[noparse][[/noparse]DEC5 rData]
DEBUG "rData = ",DEC5 rData
END
Thanks,
William
Comments
I am including some basic information regarding RS232 communications; please read the Parallax documentation
on the SERIN· and SEROUT commands to gain some insight on how a Stamp communicates via RS232. To keep
things simple I am using [noparse][[/noparse]8 data bits, no parity] and [noparse][[/noparse]polarity inverted] for the baudmode calculation for both devices.
Both the sending device and receiving device must be set to the same baud rate without regard to the
type of device - i.e., two· Stamps using RS232, two PC's or a Stamp and a PC - to correctly transmit data. The baud rate on a Stamp is set by the baudmode variable. The baudmode is a function of the speed of the device you're using and hence has a different value for a BS2sx and a BS2 even though they are using the same baud rate.
In your example, selecting a baud rate of 9600, 8 bits and no parity, polarity = inverted results in a
baudmode of 16468 for the BS2 and a baudmode of 16624 for the BS2sx.
I have attached a simple baudmode calculator, written in Visual Basic 6, to help you calculate the baudmode for your devices.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Craig Eid
www.TriadRD.com
Then use SEROUT TX2, Baud, ..........
change processors, Presto.. it'll still select the correct values!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Smile ... It increases your face value!