4 years, 10 months ago.

Timer delays and interrupts interfere with UART output

I'm having trouble getting my code to work. I'm using the RawSerial library but using timer delays or interrupts seem to mess it up. The program shown below will print nothing to the UART, at least as far as my PC can. If I comment out both the line that attaches the interrupt to the handler AND the line with the delay, then it will print 'a's to the console as expected. But with either of those statements in there, I get nothing.

Any idea what could be happening here?

include the mbed library with this snippet

#include "mbed.h"

DigitalOut myled(LED_GREEN);
RawSerial pc(USBTX, USBRX);

void uart_handler(void)
{
    pc.putc(pc.getc());    
}

int main()
{   
    pc.baud(115200);
    pc.attach(&uart_handler); //UART will print nothing unless this is commented out
    while (true) {
        wait_ms(500); //UART will print nothing unless this is commented out
        pc.putc('a'); 
        pc.putc('\n');
    }
}


Question relating to:

The FRDM-KL05Z is an ultra-low-cost development platform enabled by the Kinetis L Series KL0x MCU family built on the ARM® Cortex™-M0+ processor. Features include easy access to MCU I/O, battery-ready, ...

Can you make sure your mbed library is up to date? (Right mouse button on it, click update). And if you use regular Serial, does it work?

posted by Erik Olieman 11 Feb 2015

1 Answer

4 years, 10 months ago.

I tried out your program with latest mbed lib and it works fine for me.

Accepted Answer

Updating the mbed library worked, thanks!

posted by Sam Ryan 18 Feb 2015