12 years, 1 month ago.

Using UART1 and/or UART2 on KL25Z?

How do I use UART1 and/or UART2 in addition to UART0 on KL25Z?

I don't see any obvious way after perusing the mbed Serial and MODSERIAL code.

I see where there is a case statement that selects the UART but I'm not sure at the user level how to do that. (I'm not a very proficient C programmer yet...)

Does it relate to the third parameter when defining the pins for the serial port, where it has: const char * name = NULL ?

thanks.

2 Answers

12 years, 1 month ago.

The third parameter is a name you can give the connection. You can use that to send the standard printf commands to another seiral port. But that's another story. You simply use the other UART by defining other pins, see the pinout: http://mbed.org/handbook/Pinouts

So you can define for example Serial uart(PTD3, PTD2);

Accepted Answer
12 years, 1 month ago.

I got the alternate serial pins working, thanks much.

My next question is how to invert the serial stream coming out of the TX pin.

According to the KL25 reference manual (http://cache.freescale.com/files/32bit/doc/ref_manual/KL25P80M48SF0RM.pdf), the UART control register C3 (39.2.7 UARTx_C3) has a bit, TXINV which inverts the polarity of the serial signal. As I am using an older serial LCD which is hard coded for the opposite polarity of what the FRDM board puts out (thank Murphy), it'd be nice not to have to resort to a hardware inversion.

Is there any easy way in software to change this bit in the Serial or MODSERIAL libraries?

I don't see anything in serial api, neither I guess that MODSERIAL has this feature which is platform specific. Just set that bit directly from code.

posted by Martin Kojtal 02 Aug 2013

Martin is correct that the option isn't available directly with an api command.. Not tested but what should work:

If you use MODSERIAL (I assume you use http://mbed.org/users/Sissors/code/MODSERIAL/, since that is only one I know of that works with KL25), add to MODSERIAL_KL25Z.cpp, in initDevice:

((UART_Type*)_base)->C3 |= (1<<4);

Note that it will change then the polarity for all modserial objects used in that program.

Otherwise for both serial and modserial, figure out which UART is used, and use (replace 0 with number you need, 0-1-2):

UART0->C3 |= (1<<4);
posted by Erik - 03 Aug 2013

Using MODSERIAL and the first option above works with UART0, but if I try to use UART 1, it does not. Further, anything but PTA2 and PTA1 (USBTX and USBRX) also does not seem to work with UART0.

For the moment, this will serve me, though, for what I'm testing.

Thanks much.

posted by david dicarlo 05 Aug 2013

Regarding the UART0 connections, that is probably related to: http://mbed.org/forum/bugs-suggestions/topic/4477/, so next mbed release should have all possible connections.

Regarding the other UARTs, I checked it with the standard available serial ports: http://mbed.org/handbook/mbed-FRDM-KL25Z, and for both it seemed to work. (I only did simple check though, if the idle level was high or low).

posted by Erik - 05 Aug 2013