Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
10 years, 5 months ago.
second uart interrupt
Hello all,
Now I'm working on a project which is using 2 module. Those two are communicating with the LPC1768 using UART. I'm using uart interrupt to manage those two data. The LPC1768 have to send the data result every 50ms using third UART.
The first module coming every 25 ms and the second one coming every 1 s. I'm not sure what happen if both of them coming at the same time? I have already try to run the program and the result is the output come every 50 ms. However, the result seems like the second module interrupt (the one with data coming every 1s) never occurs.
any idea how to manage those interrupt?
thanks before. sorry for my english
The code is like this
include the mbed library with this snippet
// THIS IS THE FIRST HANDLER OCCURS EVERY 25 ms void datain1 (void){ variable1 = serial1.getc(); procedure1(); // this procedure need long time calculation // I think this procedure sometimes not yet finished but the second interrupt occurs } // THIS IS THE SECOND HANDLER OCCURS EVERY 1 s // this IRQ sometimes not occur. I have already make sure the data come every 1 s // if I turn off the first interrupt data. void datain2 (void){ variable2 = serial2.getc(); procedure2(); } void main (){ serial1.attach(&datain1); serial2.attach(&datain2); }
2 Answers
10 years, 5 months ago.
Hi Sebastianus, i think every serial port can be attached to his own interrupt function, for example this code i think it might work:
#include "mbed.h" Serial pc(USBTX,USBRX); Serial device1(p9, p10); Serial device2(p13, p14); void callback1() { // Note: you need to actually read from the serial to clear the RX interrupt pc.printf("%c\n", device1.getc()); } void callback2() { // Note: you need to actually read from the serial to clear the RX interrupt pc.printf("%c\n", device2.getc()); } int main() { device1.attach(&callback1); device2.attach(&callback2); while (1) { } }
Greetings
10 years, 5 months ago.
In general you should avoid any long computations inside the interrupt handlers. The code for procedure1() and procedure2() should preferably be executed in the main loop thus allowing further interrupts as soon as they occur. The interrupt handlers should rapidly get the serial data and store it. They set a flag to indicate a the presence of a new value and this flag is checked in the main loop and processed accordingly. You can use buffers to temporarily store the data that was received and allow asynchronous processing. This approach prevents the blocking of the 1 sec interrupt by the 25ms interrupt handler. Obviously, the required processing time for the 25ms datarate should be well below 25ms to avoid dataloss.
Please also share your code or at least a program flow.
posted by Martin Kojtal 28 May 2014