Shop OBEX P1 Docs P2 Docs Learn Events
Converting baud rate — Parallax Forums

Converting baud rate

Another FNGAnother FNG Posts: 3
edited 2008-11-09 21:05 in Propeller 1
I'm totally new to the propeller, and am not much of a programmer, so I could use some advice from anyone willing to offer it.

I have a windows program which will only communicate using standard serial baud rates. The device I need to connect it to uses 7812 baud. I've been unsuccessful in figuring out how to override the port speed on my PC once the application has opened the port. I'd bet there's a way to do it with the Win32 API, but like I said...I'm not much of a programmer.

Wanting to learn the propeller anyway, I thought I could run the FullDuplexSerial program at a standard baud rate on one cog for the PC connection (I have that working), and then setup another cog for the slower 7812 baud connection to the device. Where I'm lost is getting the data between the two cogs. This might be basic programming, but being all new to this has me scratching my head now. Any past posts you could suggest I read or any pointers would be GREATLY appreciated.

Thanks!

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-11-09 03:21
    It's so simple that no one has bothered with posts or pointers.

    Once you've set up the FullDuplexSerial ports and started them, you do:
    repeat
          char := input.rxcheck
          if char => 0
             output.tx(char)
    


    where "char" is a long variable and "input" and "output" are instances of the FullDuplexSerial object. Read the comments in the FullDuplexSerial source code for rxcheck and tx.
  • SeariderSearider Posts: 290
    edited 2008-11-09 04:33
    You will need to pay attention to flow control. When you are translating from a faster rate to to a slower rate, the faster source can send you data faster than you can transmit it out the slower port. You will either need to buffer the faster input or ensure that you have flow control working.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔

    Searider
  • Another FNGAnother FNG Posts: 3
    edited 2008-11-09 05:23
    Thanks Mike, that helps a lot. I've gotten this far...

    CON
    _clkmode = xtal1 + pll16x
    _xinfreq = 5_000_000
    
    
    OBJ
    
    input : "FullDuplexSerial"
    output : "FullDuplexSerial"
    
    VAR
    
    long char
    long char2
    long stack[noparse][[/noparse]32]
    
    PUB main
    input.start(31, 30, 0, 9600)
    cognew(output.start(1, 2, 0, 7812), @stack)   
    repeat
          char := input.rxcheck
          if char => 0
             output.tx(char)
          char2 := output.rxcheck
          if char2 => 0
             input.tx(char2)
    



    You mentioned reading comments in the source, but I haven't found them. In fact I was surprised that there was no documentation at all with FullDuplexSerial in the object exchange. Where do I find the docs?

    Searider,
    I have no flow controls, so the buffer will have to do it. Is there a way to increase the Rx buffer in the code you see above for the one instance of FullDuplexSerial that needs it, or do I have to increase the Rx buffer in FullDuplexSerial for both directions? I have the available RAM in this case, so this is more of an "efficient design" question.

    Post Edited (Another FNG) : 11/9/2008 5:41:33 AM GMT
  • StefanL38StefanL38 Posts: 2,292
    edited 2008-11-09 18:06
    Hello FNG,

    you don't need to do a cognew(output.start(1, 2, 0, 7812), @stack)
    as the startmethod ITSELF does the cognew

    start it the same way as the input
    output.start(1, 2, 0, 7812)

    As long as your input baudrate is lower than the output-baudrate
    the buffer cannot fill up

    Do have the possability to use a baudrate of 1200 or 2400 on the inputside ?

    best regards

    Stefan
  • Another FNGAnother FNG Posts: 3
    edited 2008-11-09 20:31
    The slowest the software will run on the PC side is 9600. I increased the buffers to 64 so I have plenty of room, and I think the propeller is working properly...it echos characters back fine with pins 1 and 2 tied together. I just have to test it with the device now.

    One more question (yeah, right!)... the device uses a single bi-directional serial wire. Instead of me terminating pins 1 and 2 to the same place on the device will "output.start(1, 1, 0, 7812)" work for a single wire use? Or, will it loop itself back at that pin and never leave the chip?
  • Mike GreenMike Green Posts: 23,101
    edited 2008-11-09 21:05
    From FullDuplexSerial:
    PUB start(rxpin, txpin, mode, baudrate) : okay
    
    '' Start serial driver - starts a cog
    '' returns false if no cog available
    ''
    '' mode bit 0 = invert rx
    '' mode bit 1 = invert tx
    '' mode bit 2 = open-drain/source tx
    '' mode bit 3 = ignore tx echo on rx
    


    Note that you will need to set mode bit 2 (and mode bit 3) to allow rx and tx to be on the same pin (and use a pull up resistor if there's not already one). Mode bit 3 will discard one received character for every transmitted character since they will be echoed back (because of the shared line).

    You can increase the buffers to any power of two up to 256 by adjusting a couple of bitmasks in the code and one offset in the initialization.
Sign In or Register to comment.