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.

CodeVision AVR printf function for second UART! Need Help

Status
Not open for further replies.

ECSD

Newbie level 4
Joined
Sep 30, 2004
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
96
#pragma used+

Hey Guys :
Any one out there use CodeVision C compiler with ATMEGA162 ?
I am trying hard to figure out how to use the printf, puts, scanf function for both UART. Any idea or example code ? i am using interrupt for both UART and configure it by CodeWizardAVR. But the prinf , scanf, puts not supported! Only Putchar supported for both USART. ! Urgent help needed ! Thanks
 

printf codevision

CodeWizard will generate this code for your USART1:
Code:
// Get a character from the USART1 Receiver
#pragma used+
char getchar1(void)
{
char status,data;
while (1)
      {
      while (((status=UCSR1A) & RX_COMPLETE)==0);
      data=UDR1;
      if ((status & (FRAMING_ERROR | PARITY_ERROR | DATA_OVERRUN))==0)
         return data;
      };
}
#pragma used-

// Write a character to the USART1 Transmitter
#pragma used+
void putchar1(char c)
{
while ((UCSR1A & DATA_REGISTER_EMPTY)==0);
UDR1=c;
}
#pragma used-

#pragma used+ is mean the following function after that will overwrite standard printf etc. basic routine (redirect to UART1).

I am trying hard to figure out how to use the printf, puts, scanf function for both UART.
You can't use both UART0 and UART1 for printf etc, except yopu write your own.
 

codevision printf

Hi budhy :
Thanks for your reply. Yes i understand. I am using the putchar1 and putchar0 now. But i wish to learn more in how to write my own printf1 and printf0, puts0 & puts1 and etc to over write the stdio function. Hope to get some example code from some one with experience. With the printf scanf function available for both USART, we can use to communicate with GSM modem, PC and other ASCII protocol devices more easily since ATMEGA comes with 2 USART...
I wish to overwrite the scanf to scanf0 & scanf1 so i can make use of more readable high level C in my coding for the main routine. And i hope to learn more on how to write my own function which allows me to overwrite the stdio for other devices such as SPI and I2C.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top