6 years, 5 months ago.

UART Example Code Error

I am testing one of the UART example codes from the website (see below) using the mbed online compiler and Tera Term on my Windows computer. The error I am getting is that "p28" and "p27" are undefined (duh). I didn't see a hardware pin on the pictures I've seen explaining how I need to declare these or even what they are. I'm sure it's a simple fix; I just can't seem to find the information that I need. The board used is the FRDM KL25Z. Thanks!

/#include "mbed.h"

Serial pc(USBTX, USBRX); Serial uart(p28, p27);

DigitalOut pc_activity(LED1); DigitalOut uart_activity(LED2);

int main() { while(1) { if(pc.readable()) { uart.putc(pc.getc()); pc_activity = !pc_activity; } if(uart.readable()) { pc.putc(uart.getc()); uart_activity = !uart_activity; } } }

1 Answer

6 years, 5 months ago.

Hey, please use the example and documentation here - https://os.mbed.com/docs/v5.6/reference/serial.html

As you can see, the constructor for Serial is thus:

Serial (PinName tx, PinName rx, const char *name=NULL, int baud=MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE)

So, in your example, you have declared two Serial objects. With the current code, you'd need a serial peripheral attached to both the USB UART as well as P28 and P27. As you've seen, your board does not define the pins P28 and P27. You can find valid pins here - https://os.mbed.com/platforms/KL25Z/. You'll need to match up the pins you use for your serial peripheral to some pins listed on the platform page.