Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

Re: SEROUT and SERIN

2007-06-04 by Don Kinzer

--- In AVR-Chat@yahoogroups.com, "briangregory82" <bgregory@...> 
wrote:
> SERIN: As a guess I would think I could start polling the pin
> for the first low-high transition [...]
What you've described would suffice for a primitive serial input 
function.  It would, of course, suffer from the same shortcomings as 
does PBasic's SERIN function, namely, that it doesn't cope well with 
unsolicited serial input.

A more general solution is to implement what is commonly called 
a "software UART" that is driven by a timer interrupt.  Typically, 
the timer interrupt has to occur at some multiple of the bit 
frequency, the higher the better, for best serial input results.  
(Hardware UARTs typically sample the input line as many as 16 times 
per bit time in order to accurately locate the center of the bit 
window.)  As you have recognized, serial output is simple in 
comparison.

I have successfully implemented (in assembly language) a 4 channel 
full duplex software UART that is capable of running up to two 
channels at 9600 baud and up to four channels at 4800 baud with a 
CPU clock speed of 14.7MHz.

A software UART implementation requires some sorting of queuing 
mechanism in which input characters are placed as they arrive.  The 
processor can then check the status of the queue and remove the 
received characters when it is able to do so.

The Atmel application note AVR305 describes how to implement a half 
duplex software UART.  The ideas there may be useful to you.

Don Kinzer
ZBasic Microcontrollers
http://www.zbasic.net

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.