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.
5 years ago.
Printing to serial disables RX IRQ
It seems that printing to a serial port breaks other serial ports' interrupts.
What should happen:
- LED blinks on receive
- After 5 seconds text gets printed to PC
- LED continues blinking
What actually happens:
- LED blinks on receive
- After 5 seconds text gets printed to PC
- LED no longer blinks
My board: NRF52-DK
Mbed-OS version: 5.14.0
ARM Compiler 6
The code:
#include "mbed.h" Serial pc(USBTX, USBRX); RawSerial gps(NC, P0_28); DigitalOut led(LED1, 1); void rxIrq() { led = !led; do { gps.getc(); } while (gps.readable()); } int main() { gps.baud(9600); pc.baud(115200); gps.attach(&rxIrq); ThisThread::sleep_for(5000); pc.puts("ABABABAABABABA\n"); return 0; }
1 Answer
5 years ago.
Hello Carbon,
I think it's because
return 0;
terminates the program. Try to delete it or in case you build with Mbed OS 2 (aka mbed classic) replace it with
while (true) {}
The problem was that the nRF52832 had only 1 UART peripheral. Printing to the PC caused the MCU to connect the peripheral to different pins (USBTX, USBRX) which broke the interrupt.
posted by Carbon . 04 Dec 2019