Society of Robots - Robot Forum
Software => Software => Topic started by: airman00 on October 11, 2008, 07:27:57 PM
-
Hi ,
How can I have a UART reading be taken on an interrupt ?
Meaning an interrupt on the UART Rx pin will trigger a "uartGetByte" .
I am using the ATmega168 and AVRStudio
EDIT: Found the answer http://www.societyofrobots.com/robotforum/index.php?topic=4886.msg38261#msg38261
EDIT: I still don't know the answer to the question below:
Also , if my transmission on the UART was lets say three bytes : 1 2 3. So the first byte ( 1) would trigger the interrupt to do uartGetByte , but would the uartGetByte capture the "1" byte , or would it skip it and only be able to capture the "2" byte?
Thanks.
Eric
-
Not an Atmel guy, but it's certainly got to be the same as a PIC...
You'll get the first byte. That's what the UART interrupt is for. It means "I have just received a full byte of data over the serial port. Come and get it.". "BTW - come and get it before the next full byte arrives or it will be gone."
-
To uart.h , would I just add this to enable an interrupt on Rx UART?
//Enable Transmitter and Receiver and Interrupt on receive complete
UCSRB=(1<<RXEN)|(1<<RXCIE);//|(1<<TXEN);
//enable global interrupts
sei();
and then add this to be the ISR portion
ISR(USART_RXC_vect)
{
// Code to be executed when the USART receives a byte here
}