4 years, 7 months ago.

UART dead on my FRDM-K20D50M

Hi!

A problem is really causing me issues and after a couple of hours of work I'd be really grateful for some help.

I have a FRDM-K20D50M and I can't seem to get UART to work with mbed.

The code is lifted directly from the sample:

include the mbed library with this snippet

#include "mbed.h"
 
Serial pc(USBTX, USBRX);  // tx, rx
 
int main() {
    pc.printf("Hello World\n");
}

This is all the code there is.

Symptoms: I can't seem to get this simple message to show up on my terminal after uploading the code and pressing the reset button and/or restarting it by removing the USB cable. What DOES show up on the COM port, in case I change the PINs in the Serial device initialization, is the message that there the pins are not properly setup. This is a message from the OpenSDA IC through UART, so I'm positive that everything is ok on the PC side (the drivers and my terminal setup).

I tried changing the pins to D1/D0 (or PTE1/PTE1 for mbed which are TX/RX for UART1) to see if there might be a problem with UART0 and checked the output there with a logic analyzer. The TX line goes low on reset as expected, but when it comes out of it, it goes to high and stays there..

Only other thing I've tried is LED toggling - which seems to work splendidly.

I also tried the USBSerial.h library which also doesn't seem to work.

I'd be really, really grateful for any help you can provide. Is there perhaps an important initialization sequence I'm missing here? This is my first time trying something like mbed, I usually work on a lower level so I have some experience but this is leaving me stumped.

http://developer.mbed.org/platforms/FRDM-K20D50M/

I'm working with this board at the moment using serial pc, working fine up to 230400.

Try adding pc.baud(230400); in your 'main' and set your terminal to match. I think default is 9600. Also make sure you have the latest Mbed library loaded.

Forgot to mention, after you have downloaded your program code, you will need to reset the terminal, otherwise no display.

posted by Paul Staron 25 Feb 2015

Thank you for your input. Completely restarting the entire project and trying the code from mr. Tanaka's post made it work on 9600. It also works on the faster baud rate you suggested. Thanks!

posted by Benjamin Jerman 26 Feb 2015
Comment on this question

1 Answer

4 years, 7 months ago.

Hi,
I have just tried your code, and it worked on my FRDM-K20D50M without modification.

Meantime, what I noticed is that your program writes only a single line and be finished,
so checking the action may not be easy.

How about modifying the code as follow?

#include "mbed.h"

Serial pc(USBTX, USBRX) ; // tx, rx

int main() {
    pc.printf("Program Started\n\r") ;
    while(1) {
        pc.printf("Hello World\n\r") ;
        wait(1) ;
    }
}

If you remove the line "wait(1) ;" it will be easier to probe the signal.

In case, both your code and mine do not work, may be you need to check the HW.

moto

Directly copying this code worked. I completely purged all the includes from the program and imported the mbed library from the start, copied your code verbatim and... Things seem to work now! Both the UART0 and the UART1. But I have no idea what went wrong the first time around.

Thank you mr. Tanaka! Problem solved! :)

posted by Benjamin Jerman 26 Feb 2015