Shop OBEX P1 Docs P2 Docs Learn Events
My program errors when trying to send RS232 data from a BS2 to a BS2sx — Parallax Forums

My program errors when trying to send RS232 data from a BS2 to a BS2sx

wmtell1wmtell1 Posts: 14
edited 2009-02-11 04:32 in BASIC Stamp
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

Comments

  • Craig EidCraig Eid Posts: 106
    edited 2009-02-09 23:46
    William,

    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
  • wmtell1wmtell1 Posts: 14
    edited 2009-02-10 16:46
    Thak you for the explanation. I set the baud rate·for both devices to 9600 using the settings from your baudmode calculator and everything works! Have you considered posting the calculator - I'd expect that other could benefit from it?
  • MrBi11MrBi11 Posts: 117
    edited 2009-02-11 04:32
    If you add Compiler directives to your program as follows it'll do the work for you!

    
    #SELECT $STAMP
      #CASE BS2, BS2E, BS2PE
        T1200       CON     813
        T2400       CON     396
        T9600       CON     84
        T19K2       CON     32
        T38K4       CON     6
      #CASE BS2SX, BS2P
        T1200       CON     2063
        T2400       CON     1021
        T9600       CON     240
        T19K2       CON     110
        T38K4       CON     45
      #CASE BS2PX
        T1200       CON     3313
        T2400       CON     1646
        T9600       CON     396
        T19K2       CON     188
        T38K4       CON     84
    #ENDSELECT
    
    Inverted       CON     $4000
    Open            CON     $8000
    
    Baud            CON     T9600  + Inverted
    
    



    Then use SEROUT TX2, Baud, ..........

    change processors, Presto.. it'll still select the correct values!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Smile ... It increases your face value!
Sign In or Register to comment.