Rules | Recent posts | topic RSS | Search | Register  | Log in

Multiple UARTs in ATMega161

 
Post new topic  Reply to topic    EDAboard.com Forum Index -> PC Programming and Interfacing
Author Message
jetal



Joined: 20 Apr 2002
Posts: 19
Location: Australia


Post12 Dec 2002 11:36   Multiple UARTs in ATMega161

I am contemplating on how to write an experimental application in C that uses both hardware UARTs in the Mega161 AVR chip. I will be using ICC AVR for development.

From the ICCAVR help file/manual, I can see that I can use putchar() and getchar() to send and receive characters. However these functions do not define which UART the character is being sent to or received from.

To me it looks like I have to write my own modified putchar0() and putchar1() functions to write to the different UARTs and similar for receiving. I can see that its not a difficult job doing this, but is this the easiest method or is there something better?

If anyone has done something similar it would be nice to see a code snippet.
Back to top
Stark



Joined: 10 Aug 2001
Posts: 86


Post12 Dec 2002 11:52   

Yes it is true,but you will experience you can't use standard formatter such as printf() because it recalls lower level function such as putchar()
Stark
Back to top
jetal



Joined: 20 Apr 2002
Posts: 19
Location: Australia


Post12 Dec 2002 13:06   

I do understand that higher level functions like printf() call lower level functions like putchar() and if I were to output a string with puts() it would also invoke putchar().

I have done custom putchar() to implement an interrupt driven putchar() in an 8051. This did not replace the library putchar() - I gave my function a different name.

The real point of my query: is this the most elegant or efficient or best way? I am a "raw" programmer and I'd like to know how someone with more experience would approach the problem.
Back to top
johnyaya



Joined: 30 May 2001
Posts: 149
Helped: 17
Location: YoyoDyne


Post12 Dec 2002 17:49   

I would generate write and read functions that accept parameters for port number and data to send (ie. wrSIO(port,length,char*) ). Independent buffers for each uart. Seperate interrupt driven low-level routines for I/O. Don't use printf() to format, use sprintf().
Back to top
Post new topic  Reply to topic    EDAboard.com Forum Index -> PC Programming and Interfacing
Page 1 of 1 All times are GMT + 2 Hours


Abuse
Administrator
Moderators
topic RSS 
sitemap