DPRG
DPRG List  



[DPRG] AVR Software UART

Subject: [DPRG] AVR Software UART
From: Jon Hylands jon at huv.com
Date: Mon Feb 18 04:46:06 CST 2008

On Mon, 18 Feb 2008 01:41:08 -0600 (CST), scott at lighthouse21.com wrote:

> I'm attempting to interface additional serial devices to an Atmel
> AVR, the hardware UART is already in use.  I basically need a
> bit-banged TX only module.  The only examples I can find still rely
> on timers which are also in use.  Does anyone have a starting point
> for developing this?  I'm clocking the AVR at 1MHz and need to put
> out 9600 baud.

It should be simple to do - I've bit-banged this in assembler for a PIC
(many years ago). You just need reasonably accurate delay loops.

At 9600 baud, you're looking at a shade over 104 us per bit. So do
something like this: (psuedo C code)

void oneBitDelay ()
{
	// delay for 104 us
}

void sendByte (byte)
{

	// send the start bit
	setPinLow (pin);
	oneBitDelay ();

	for index = 0 to 7
	{
	// send each bit
	if (isBitHigh (byte, index))
		setPinHigh (pin);
	else
		setPinLow (pin);
	oneBitDelay ();
	}
	// now send the stop bit
	setPinHigh (pin);
	oneBitDelay ();
	return ();
}

That should get you close enough to work fine at 9600 baud... To send a
string, just call this function with each character of the string.

Later,
Jon

--------------------------------------------------------------
   Jon Hylands      Jon at huv.com      http://www.huv.com/jon

  Project: Micro Raptor (Small Biped Velociraptor Robot)
           http://www.huv.com/blog

More information about the DPRG mailing list

Copyright © 1984 - 2006 Dallas Personal Robotics Group. All rights reserved.
Website Design by NCC

For the latest robot news visit robots.net