Shop OBEX P1 Docs P2 Docs Learn Events
Change Baud rate — Parallax Forums

Change Baud rate

10gigbill10gigbill Posts: 79
edited 2012-03-10 15:31 in General Discussion
I am building a serial test generator to send out serial commands. I would like to have several baud rates (say from reading a dip sw) Since "Baud" is a constant, how do I get around this? (without writing different subs for each baud rate)

Comments

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2012-03-09 18:47
    It doesn't have to be a CONstant.
    It could be a variable.

    baudrate var Word

    baudrate = 9600
    SEROUT Sio, Baudrate, ["Bingo!"]

    baudrate = 4800
    SEROUT Sio, Baudrate, ["Bango!"]
  • wasswass Posts: 151
    edited 2012-03-09 19:21
    The SX/B manual says that the baud rate does have to be a constant, am I missing something?

    While I've never tried this, take a look in the manual at the second example in the INTERRUPT command. It shows how to receive into a buffer using ASM code. It further shows the baud rate as a constant, but it would not be hard to modify this for a variable baud rate and for sedning instead of receiving. There are all SX library returns for complete UART functionality and a lot more here:

    http://www.piclist.com/techref/scenix/lib/io/osi2/serial/rs232_sx.htm
  • 10gigbill10gigbill Posts: 79
    edited 2012-03-09 20:25
    I tried a var and get an error. It seems baud has to be a string constant. must be some way to change baud rate on the fly....?
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2012-03-10 13:45
    OK, sorry, I haven't spent any time on SX/B since last summer.
    I was looking at my XBee remote control programming from then.
    The baudrate doesn't have to be a declared CONstant (it's a "string constant").

    SEROUT xmt_pin, T9600, "!"

    The value to be transmitted, that in quotes, could be a byte variable instead.

    Read your DIP switches before you transmit and branch to a FUNC or SUB with the desired baudmode plugged in?
    sending:
      xmtbyte = $F0
    
      IF dipsw = 0 GOTO lowbps
      GOTO highbps   ' =1
    
    lowbps:
      SEROUT xmtpin, T2400, xmtbyte
      GOTO sending
    highbps:
      SEROUT xmtpin, T9600, xmtbyte
      GOTO sending
    
  • 10gigbill10gigbill Posts: 79
    edited 2012-03-10 15:31
    Thanks P J

    I think that might be the way to go. I'll plug that in and see.

    Bill
Sign In or Register to comment.