i am trying to get my USART to work in my lil' atmega48.
did the following already .
void USART_init(unsigned int ubrr)
/*Set baud rate */
UBRR0H = (unsigned char)(ubrr>>8);
UBRR0L = (unsigned char)ubrr;
/*Enable receiver and transmitter */
UCSR0B = (1<<RXEN0)|(1<<TXEN0);
//Enable double speed
UCSR0A |= (1<<U2X0);
/* Set frame format: 8data (UCSZ00), 1stop bit(USBS) , Parity : none (UPM) */
UCSR0C &= ~(1<<UMSEL01) & ~(1<<UMSEL00) & ~(1<<UPM01) & ~(1<<UPM00) & ~(1<<USBS0) | (3<<UCSZ00);
void USART_Transmit( unsigned char data )
/* Wait for empty transmit buffer */
while ( !( UCSR0A & (1<<UDRE0)) )
/* Put data into buffer, sends the data */
UDR0 = data;
unsigned char USART_Receive( void )
/* Wait for data to be received */
while ( !(UCSR0A & (1<<RXC0)) )
/* Get and return received data from buffer */
I would be running at a baud rate of 9600 using a 8N1 frame.
Now the problem is, i want to receive data/info from the hyperterminal (thru the serial port) to trigger some things on the atmega48. Data that would be sent from the hyperterminals are single characters.
How can i read these characters once i received them ?
can i use functions like getchar() ? how can i do that ?
thank you !