Author Topic: UART on Interupt  (Read 1773 times)

0 Members and 1 Guest are viewing this topic.

Offline airman00Topic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 3,653
  • Helpful? 21
  • narobo.com
UART on Interupt
« 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

« Last Edit: October 11, 2008, 07:29:26 PM by airman00 »
Check out the Roboduino, Arduino-compatible board!


Link: http://curiousinventor.com/kits/roboduino

www.Narobo.com

Offline ArcMan

  • Supreme Robot
  • *****
  • Posts: 519
  • Helpful? 4
  • Mmmm... Plasma
Re: UART on Interupt
« Reply #1 on: October 11, 2008, 08:28:01 PM »
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."

Offline airman00Topic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 3,653
  • Helpful? 21
  • narobo.com
Re: UART on Interupt
« Reply #2 on: October 11, 2008, 08:31:41 PM »
To uart.h , would I just add this  to enable an interrupt on Rx UART?


Code: [Select]
//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

Code: [Select]
ISR(USART_RXC_vect)
{
   // Code to be executed when the USART receives a byte here
}
« Last Edit: October 11, 2008, 08:33:24 PM by airman00 »
Check out the Roboduino, Arduino-compatible board!


Link: http://curiousinventor.com/kits/roboduino

www.Narobo.com

 


Get Your Ad Here