2 weeks 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;
}

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
Comment on this question

1 Answer

1 week, 4 days 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) {}


You need to log in to post a question