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.
7 years, 12 months ago.
Error attaching interrupt to UART on LPC178 using mbed-os
Hi,
I am trying to reproduce example three from https://docs.mbed.com/docs/mbed-os-api-reference/en/5.2/APIs/interfaces/digital/Serial/ to attach a interrupt on receive to one of the serial ports on the LPC1768. Here is the code for reference:
The code
#include "mbed.h" DigitalOut led1(LED1); DigitalOut led2(LED2); Serial pc(USBTX, USBRX); void callback() { // Note: you need to actually read from the serial to clear the RX interrupt printf("%c\n", pc.getc()); led2 = !led2; } int main() { pc.attach(&callback;); while (1) { led1 = !led1; wait(0.5); } }
The code shown works fine if I am using mbed as the library. However, using the same code with mbed-os compiles properly, but it does not work. After uploading, LED1 blinks as expected. If I send a character to the serial port, it stops blinking, and I do no receive anything on the terminal.
I have been fighting with this for quite some time now, so any help will be greatly appreciated :)
Thanks a lot!
1 Answer
7 years, 12 months ago.
By coincidence Ive found myself in the same misery tonight but with a K64F...IF you make any progress let me know and I will post back here if I can make any progress.
Apparently, for some reason I don't know, the Serial library putc() and getc() methods do not work inside interrupt callbacks when using the RTOS. However, the library RawSerial does support them. Simply changing Serial pc(USBTX, USBRX); to RawSerial pc(USBTX, USBRX) solved the problem.
posted by 01 Dec 2016
Hi everybody,
I have read your post because i have the same problem. I have replace Serial pc by RawSerial and my système doesn't work.
Do you have an idée to resolve the problem ?
posted by momo smith 02 Jun 2017