Log in

View Full Version : EDU Demo Code: Serial Data Transmitter Using a State-Machine


Kevin Watson
28-12-2003, 03:05
I've written an example software-based serial data transmitter that shows how to implement a state-machine. This transmitter can be used to send asynchronous serial data to external devices using a digital I/O pin. Though it has many uses, I specifically wrote this to send data to a serial LCD. From the header:

This software demonstrates the use of a timer and associated interrupt to precisely clock a software-based serial transmitter which can be used to communicate with other common serial devices like serial LCDs.

In this example we'll setup a timer to generate an interrupt at a rate of 2400 interrupts per second. In response to this interrupt, the microcontroller will execute a specific piece of code called an interrupt handler (see user_routines_fast.c). Within this interrupt handler is a software state-machine that emulates the transmitter section of Universal Asynchronous Receiver/Transmitter (i.e., common PC serial port) running at a baud rate of 2400 bps. The output can be configured to use positive logic for communication with TTL-level serial receivers or negative logic for communication with RS-232 devices that are also compatible with inverted TTL signaling. The TTL serial port on the EDU robot controller can only signal using positive logic.

This code has been sucessfully tested with Scott Edwards Electronics' (http://www.seetron.com (http://www.seetron.com/)) BPP-420VY and SGX-120L serial LCDs (other than being a satisfied customer, the author has no relationship with this company).

In the zip file I've also included a PDF document that shows how the generated serial waveform should look and how each serial bit maps to a specific state of the state-machine. The code can be found here: http://kevin.org/frc

-Kevin

Kevin Watson
28-12-2003, 13:52
I've updated the ZIP file to include a RS-232 serial communications primer.

-Kevin

KevinB
28-12-2003, 17:02
Thanks for posting this!

Our electrical team actually had the idea of using an LCD for feedback -- and this will make things easier on us!

Kevin Watson
28-12-2003, 22:56
Thanks for posting this!

Our electrical team actually had the idea of using an LCD for feedback -- and this will make things easier on us!
Cool, I'm glad you can use it. Before you start looking at LCDs with serial interfaces, make sure that it supports TTL-level signaling and the baud rates that this software supports. For ease of use, I'd suggest looking at LCDs that support serial terminal-like interfaces too.

Of course, you're best bet is to find a LCD that can use the hardware serial ports built into the EDU controller (and presumably the full-size controller). If you want to use the dedicated TTL-level serial port, make sure that your LCD supports non-inverted TTL-level signaling.

Here is an great web page that discusses the different ways to communicate with a serial LCD: http://www.seetron.com/ser_an1.htm

-Kevin