Arduino Forum

Using Arduino => Networking, Protocols, and Devices => Topic started by: michastro on Feb 12, 2013, 01:44 pm

Title: Serial interupt (SOLVED)
Post by: michastro on Feb 12, 2013, 01:44 pm
Hello,
I'm working with UNO32, and I would like to use serial communication but through interrupt. For example, if a serial data arrived, an interrupt is trigger, and I process the data.
Thanks
Title: Re: Serial interupt
Post by: johnwasser on Feb 12, 2013, 02:50 pm
The chipKIT "UNO32" is not an Arduino and does not have an ATmega processor so you're going to have trouble getting help here for it.  I would start reading the datasheet for the PIC32MX320F128 to see how to work with the hardware serial port.  Good luck!
Title: Re: Serial interupt
Post by: PaulS on Feb 12, 2013, 03:23 pm
Serial data delivery is already interrupt based. Why is not checking Serial.available() in loop() sufficient?
Title: Re: Serial interupt
Post by: michastro on Feb 12, 2013, 04:33 pm
For example with the timer2, I use:
void __ISR(_TIMER_2_VECTOR,IPL3AUTO) comms2_handler(void)
{
}
perhaps something like:
void __ISR(_UART_1_VECTOR,IPL3AUTO) comms2_handler(void)
{
}
?????

Title: Re: Serial interupt
Post by: PaulS on Feb 12, 2013, 04:47 pm
S   e   r   i   a   l      d   a   t   a      a   r   r   i   v   e   s      s   l   o   w  l   y.

I still don't see why the arrival of one byte needs to interrupt the Arduino. What else is it doing?
Title: Re: Serial interupt
Post by: michastro on Feb 12, 2013, 05:42 pm
I need this interrupt because in the same time I have several timers, and I want to manage special priorities order.
I have found the solution:

#include <plib.h> /* this gives the i/o definitions */

boolean received;

void setup()
{
received=false;
Serial.begin(38400);
}

void loop()
{
if (received)
{
  Serial.println("RECEIVED!!!");
  received=false;
}
}

extern "C" {
void __ISR(_UART_1_VECTOR, ipl4) U1_ISR(void)
{
  if(mU1RXGetIntFlag())
  {
    // Clear the RX interrupt Flag
    mU1RXClearIntFlag();

    // Handle Character
    received=true;
  }
}
}
and now I can choose the IPL I want!

Thanks