Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

How to use printf and puts functions in IAR compiler for AVR

Status
Not open for further replies.

mike2002

Member level 2
Joined
Sep 16, 2002
Messages
47
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
c/c++ programming
Activity points
328
I*A*R FOR A*V*R

Hello,
Does anybody has experience with IAR Compiler for AVR?
I am having trouble, how to use printf and puts functions.
I did set BAUD rate and UART for MEGA8. Functions compiled fine but noting out on serial port?
Thanks,

:cry:
 

cancel

Full Member level 5
Joined
May 27, 2001
Messages
251
Helped
15
Reputation
30
Reaction score
4
Trophy points
1,298
Activity points
1,878
printf

hi .. i am doing this other way ...

sprintf(buf, "\nTempC= %d degrees C\n", (int)temp_lsb ); // print temp. C
sends(buf)

where

void send(char TX_Char)
{//this sends TX_Char to UART
UDR = TX_Char;
while(!(USR&32)); //wait while tx buffer empty
}
void sends(char *string)
{
unsigned int n;
for(n=0;n<strlen(string);n++)
send(string[n]);
}

i have never used printf directly to seriel .. always via register ...

regards

cancel
 

solvarg

Full Member level 2
Joined
Feb 15, 2002
Messages
120
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Location
Sweden
Activity points
853
I*A*R FOR A*V*R

printf calls the library function putchar, which must be adapted for the target hardware configuration.
The function is supplied in source format in the file putchar.c
Look in the HELP for detailed description.

Regards
 

newmania

Member level 1
Joined
Sep 29, 2002
Messages
37
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
228
Re: printf

cancel said:
hi .. i am doing this other way ...

sprintf(buf, "\nTempC= %d degrees C\n", (int)temp_lsb ); // print temp. C
sends(buf)

where

void send(char TX_Char)
{//this sends TX_Char to UART
UDR = TX_Char;
while(!(USR&32)); //wait while tx buffer empty
}
void sends(char *string)
{
unsigned int n;
for(n=0;n<strlen(string);n++)
send(string[n]);
}

i have never used printf directly to seriel .. always via register ...

regards

cancel

What is the differece between using register and directly serial port commands?
 

mike2002

Member level 2
Joined
Sep 16, 2002
Messages
47
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
c/c++ programming
Activity points
328
puts & printf

Thanks to all of you,
I did revised putchar function and included to my code:
int putchar(int c)
{
if (c == '\n')
putchar('\r');
while ((UCSRA & (1<<UDRE)) == 0) // UDRE, data register empty
;
UDR = c;
return c;
}
Now all lib. functions related to serial I/O functioning.
I guess getchar() need to be revised also to get other way communication? :lol:
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top