Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Multiple UARTs in ATMega161

Status
Not open for further replies.

jetal

Junior Member level 1
Junior Member level 1
Joined
Apr 20, 2002
Messages
17
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Australia
Activity points
125
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.
 

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
 

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.
 

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().
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top