I have been trying to find a solution for UART receive interrupt for my UNO board and I came across a possible solution in : PCInt
I did a small editing in the following portion of the code to make it work for UART.(code works like a loop-back test)
void RXint(void) {
char k;
if(Serial.available()>0)
{
k=Serial.read();
Serial.print(k);
}}
void setup()
{
Serial.begin(9600);
PCattachInterrupt(0, RXint, FALLING);
}
void loop()
{}
The code works pretty well with one big drawback. The character displayed is having one char delay, what i mean is that for the following input
qwerty
output is
qwert
That means if I enter the 5th char,the output will be 4th one. When the first input is given, it doesn't show output till the second input is entered.
Can someone help me out with this
(This is only a test code, the interrupt part is to be used in a larger code where the loop() carries out different tasks and interrupt is to be raised when data is received via UART) .
RXint→loop. It should work like a charm.Serialalready handles the UART interrupt pretty well. Trying to manage the incoming data in an interrupt is misguided.loop.Serialobject already provides an interrupt that does exactly what you want: it stores the incoming data in a RAM buffer. It makes little sense to add a second buffering layer of your own. “I cant use Serial.event() as it checks only at the ending ofloop”. Checking at the end ofloop()is fine, unless yourloop()is too slow. If this is the case, then your real problem is: too many blocking calls. It's not a problem about serial interrupts at all.External RAM(from where further processing is done). Of course theloop()is slow as it needs to be reading RTC and pushing data to other devices and I cant miss a character in sequence that I am receiving. Cause of these reasons I am trying to implement interrupt.