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.
8 years, 11 months ago.
FRDM-KL25Z mbed serial with Interrupt doesn't work
I am trying to use serial with interrupt. The program doesn't work on FRDM-KL25Z. However the same program works well on the platform (Nucleo-F411RE) I tried.
2 Answers
8 years, 11 months ago.
#include "mbed.h" //#include "rtos.h" Serial pc(USBTX, USBRX); DigitalOut myLED(LED1); void Rx_interrupt() { myLED=1; while (pc.readable()) { pc.putc(pc.getc()); } myLED=0; return; } int main() { myLED = 0; /*Try without Serial::RxIrq - that works for me.*/ pc.attach(&Rx_interrupt); //pc.attach(&Rx_interrupt, Serial::RxIrq); while(1){ } }
Try the code above.
Regards
8 years, 11 months ago.
You need to delete RTOS from your program folder, or use RawSerial instead of Serial. Serial + RTOS + IRQs do not work properly. And yes, you are using RTOS even if you don't include it in your main file, including the files in your program also makes sure they get compiled and affect your program.
Thanks Erik. Will test your suggestion. But I have a question. Since the same program works on Nucleo-F411RE, does that mean, there is likely a bug in FRDM-KL25Z mbed port?
posted by 21 Jan 2016Well thats a good one, I would expect the same problem on the F411. Maybe it depends on how the compiler decides to work when no #include statement is present.
For sure I would first try it without the RTOS, and to be sure with a clean compile (use compile all from the compile drop down menu if you use the online compiler).
posted by 21 Jan 2016Hi Erik, I tested your suggestion and removed the RTOS library from the program folder. My program with Serial, works correctly. Included RTOS library. My program with RawSerial works correctly. I am yet to test RTOS to be used in my program.
I also understood the reason for my program working on Nucleo-F411. In the program folder the RTOS library was not present.
Thanks a lot.
posted by 21 Jan 2016
Considering you have commented out RTOS: Do you have RTOS library in your current program folder?
posted by Erik - 21 Jan 2016The RTOS library is present in the folder. But the program doesn't use it.
posted by Hemant Joshi 21 Jan 2016