Shop OBEX P1 Docs P2 Docs Learn Events
Full Duplex Virtual UART Demo — Parallax Forums

Full Duplex Virtual UART Demo

pjvpjv Posts: 1,903
edited 2008-02-05 20:24 in General Discussion
Hi All;

Several days ago there was a thread regarding state machines and their usefulness. A year ago I had posted an example of such a system demonstrating simultaneous transmitting and receiving UARTs, and Jon Williams stated he was unable to get the receiver portion to work..... I had tested the transmitter, but not·the receiver·before posting, and that did indeed·was an error, I had omitted a line.

Sorry about that!

So I looked into it, and·attached is the repaired code.... fully tested to transmit and receive at 9600 at the same time. Oh the wonders of state machines!

The scheduler is set to: every 100 mSec the transmitter rattles off a string of two ASCII characters, a space, a linefeed and a carrige return, one character per 10 mSec,·while the receiver simply returns a value into a one character receive buffer for the user to deal with at will.

The scheduler that times all the activity is run at a 2 uSec interrupt rate, and this creates a baud time of 100 uSec for the system... slightly off the proper 104 uSec, but almost always workable. This time permits other·events triggered by the scheduler to be properly timed.

If the user requires the precise baud timing of 104 uSec, then simply select the appropriate interrupt constant, realizing that this will put the scheduler timing off by the same amount If you chose this, then also select the appropriate sample interval for the receiver;·pick your poison.

Also if you have a multi channel oscilloscope, you can uncomment the "ShowSample" call, and observe the time instant that the UART samples the incoming data stream on RA.2

Hope this scheduler and state machine concept is of interest to the readers.

Cheers,

Peter (pjv)

Comments

  • dkemppaidkemppai Posts: 315
    edited 2008-02-05 20:12
    pjv said...
    Hi All;

    Several days ago there was a thread regarding state machines and their usefulness. A year ago I had posted an example of such a system demonstrating simultaneous transmitting and receiving UARTs, and Jon Williams stated he was unable to get the receiver portion to work..... I had tested the transmitter, but not·the receiver·before posting, and that did indeed·was an error, I had omitted a line.

    I wrote some similar code a while back...· I had been thinking about posting it. I may throw it up now. It's two simultaneous recieve/xmit UARTS each with FIFO buffering. Each Uart baud rate can independently set·in with·from 1200 to 19200 baud in the standard increments (I have also expanded that to 57600Baud).·Using the routine is as simple as placing a byte in W, and calling a routine. To read a byte from a port, call the routine and check Z. If Z = 1, no data was read into W.·Ram banks are restored·to what they were when calling any routine.· Oh, yeah, all of the code is packed in to two·upper half code pages...···· ...the only catch is the interrupt frequency with a 50Mhz resonator had to be bumped up a little to match the standard baud rates. (Something like RTCC every 216 clock cycles).

    I'll try to clean it up if a get a chance...··· ...I had·sort of forgotten about it until you reminded me...

    -Dan


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

    "A saint-like quantity of patience is a help, if this is unavailable, a salty vocabulary works nearly as well." - A. S. Weaver
  • JonnyMacJonnyMac Posts: 9,218
    edited 2008-02-05 20:24
    I enjoyed working with (and learning from) Peter's code and would love to see what you have to offer, Dan.
Sign In or Register to comment.