In SX Microcontrollers, SX/B Compiler and SX-Key Tool, Peter Van der Zee wrote: 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) ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=246255 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2008 (http://www.dotNetBB.com)