help on USART

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Currently I working on a very simple projekt and I found a code snippet for it. This code uses high level USART functions like puts_P() and printf() so I wanted to experiment with these a little.
So far I managed to send data on USART with my own simple code, on the very same hardware, with same settings, but not with these high level library functions.
What am I missing?

On compiling no error or warning.


/*
*	AT90CAN128 @ 16MHz 
*
*
*
*/



#include 
#include 
#include 
#include 

void Send_UART(char uart_data);
void timer1init(void);

	
int main(void)
{
 
	
	DDRA = 0xFF;
	PORTA = 3;

	UBRR0L=103;	// 9600 baud @16 MHz
	UCSR0B=(1<<RXEN0)|(1<<TXEN0); // 8bit,1Stop, no parity


	timer1init();
	sei();

	puts_P (PSTR("Hello World\n"));
	
	while(1);
}

// Send a byte in every second.
ISR (TIMER1_COMPA_vect)
{
	volatile unsigned char a;
	a= PINA;
	a++;
	PORTA =a;
	Send_UART(a);

//	
}


void Send_UART(char uart_data)
{
	while (!(UCSR0A&(1<<UDRE0))); // Continue if UDRE=1, that means
								// UDR register is empty
	UDR0=uart_data;					// send Dataflash status reg
	while (!(UCSR0A&(1<<TXC0)));	// Wait until it is sent
	UCSR0A=UCSR0A|(1<<TXC0);		// Clear TXC flag

}

// 1sec timing: 
// F= Fclk/(N*(OCR1A+1))
// 16'000'000/256=62500
// OCR1A=62499= 0xF423
void timer1init(void)
{

	OCR1AH=0xF4;
	OCR1AL=0x23;

	TCCR1B = (1<<WGM12)|(1<<CS12);

	TIMSK1 = (1<<OCIE1A);
}
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Look up 'fdevopen' or similar sounding macros.

Once you associate your USART functions with streams, all the functions will work.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So you have working hardware. Great. Now you can look into the example folder for winAvr stdiodemo (C:\WinAVR-20100110\doc\avr-libc\examples\stdiodemo in my computer) and you will see how to use the stdio functions.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly