So, it’s pretty common to need two serial ports (say GPS and GPRS, GPRS and serial LCD, GPS and XBee…there are lots more, I’m sure.)
I am vaguely aware that there are different solutions people have written to “bit-bang” serial using a couple of GPIO ports on an AVR. My questions are:
What bit bang libraries are available, how well do they work, how hard are they to use? I’m using WinAVR tools - anything you know that is compatible with those is especially appreciated.
What has your experience been with creating a 2nd “virtual” serial port on an ATMega128, for example.
Any timing issues to watch out for? What are the practical speed limits of this type of solution?
In some cases, I know I could share a single serial “bus”, but I don’t always have control over the devices/firmware of those on the bus, so the serial bus might work for some things, but in general, I think I often need a 2nd serial port on my AVRs. I don’t have a good sense of the best way to get to that goal.
Help and advice is appreciated from any who have done it. Thanks.
Yes, thanks. I’ve found one possibility but it would need adapting. Was hoping there was something fairly general purposes/portable out there already, but I’m not sure there is. Like any typical (lazy?) software guy, I want to try to find it first, write it next if I have to.
Here is the only candidate I’ve found as a starting point:
And a related question is specific to the AVR MT 128 from Olimex. On that board, the 2nd USART, well USART0 to be exact, is wired to the ICSP connector.
I use it for programming the device, but is there any reason why pins 1 and 9 of the ICSP connector, which are wired to RXD0 and TXD0 respectively, could not be used for a 2nd serial port when the application is running?
If so, then I don’t really need a software UART. I just don’t know what I can safely abscond with to suit my purposes without frying something. If I used the ICSP serial lines, is there something I need to do with any other ICSP line in order to keep it from thinking it’s in a programming mode?
You’ll have to disconnect the external serial device when using the ISP function, i’d think, unless you have some sort of RS232 driver that can be disabled with a jumper or some such.
I just verified that using the TXD0 and RXD0 pins on the AVR MT 128 ( pins 1 and 9 on the icsp port ) work just fine as the 2nd serial port. I’m using it to read a 4800 baud gps and spitting it out the UART1 port at 9600.
there are a few examples of code for an AVR to parse the NMEA 183 “sentences” of GPS data. Some in C, some in Zbasic and others. It’s not hard to do from scratch.
For sure, just put resistors on the UART side of any of the ISP pins so that your IS Programmer can override it.
Edward
landon:
And a related question is specific to the AVR MT 128 from Olimex. On that board, the 2nd USART, well USART0 to be exact, is wired to the ICSP connector.
I use it for programming the device, but is there any reason why pins 1 and 9 of the ICSP connector, which are wired to RXD0 and TXD0 respectively, could not be used for a 2nd serial port when the application is running?
If so, then I don’t really need a software UART. I just don’t know what I can safely abscond with to suit my purposes without frying something. If I used the ICSP serial lines, is there something I need to do with any other ICSP line in order to keep it from thinking it’s in a programming mode?
This is just for reference for anyone who needs more UARTs.
The Procyon AVRlib has a software based UART that utilizes the AVR’s timer output compare and input capture or external interrupts. I have used it with an Atmega8 and it works great.
I personally think it is better than the one found on avrfreaks. With the correct crystal, you can obtain any baud rate with 0% error even though it is software based.