easiest way to implement lpuart rx code frdm-kl27

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

easiest way to implement lpuart rx code frdm-kl27

1,645 Views
mikemitchell
Contributor I

simple way to set up lpuart rx receiver for kl27 frdm-kl27

0 Kudos
Reply
6 Replies

1,357 Views
victorjimenez
NXP TechSupport
NXP TechSupport

Hello Mike,

You can download the MCUXpresso SDK for the FRDM-KL27. The MCUXpresso SDK is a comprehensive software enablement package designed to simplify and accelerate application development with NXP’s LPC and Kinetis microcontrollers and i.MX RT crossover processors based on Arm Cortex-M cores. The MCUXpresso SDK includes production-grade software with integrated RTOS (optional), integrated stacks and middleware, reference software, and more. 

Within the SDK you will find the drivers for the lpuart along with examples that show how to implement these drivers. 

pastedImage_2.png

Hope it helps!

Victor.

-----------------------------------------------------------------------------------------------------------------------

Note: If this post answers your question, please click the Correct Answer button. Thank you!

----------------------------------------------------------------------------------------------------------------------- 

0 Kudos
Reply

1,357 Views
mikemitchell
Contributor I

Thanks Victor, but in this system this is the receive board to the FRDM-KL27 that transmits. All code done in KDS with PEx.

Mike

0 Kudos
Reply

1,357 Views
victorjimenez
NXP TechSupport
NXP TechSupport

Hello Mike,

I recommend you to migrate to our newest software (MCUXpresso SDK) and IDE (MUCUXpresso IDE) that are fully supported and continuously upgrade. Within the SDK you will find examples of both UART and LPUART peripherals. You can use these examples to see the easiest way to set up LPUART Rx. 

Regards,

Victor. 

0 Kudos
Reply

1,357 Views
mikemitchell
Contributor I

Hi Victor,

I didn’t realize I was posting question, I thought I was searching the forum til I hit enter. I am a newbie to using C and the project I am working on is an extension of an existing product at work which has all been developed with KDS, therefore I am stuck with it.

I have tried loading the lpuart driver examples, but was unable to use Processor Expert with them and unable to find my way through it without. I was looking for example code that would allow me to tailor to my application.

Currently it looks like it is set up in PEx but when it doesn’t work I am not sure where to go with it. I have 2 FRDM-KL27 boards and have successfully created a Tx driver with modulated output, now trying to set up Rx board to decode the characters I am sending with Tx.

If you know of an easy route to achieving this I’d greatly appreciate.

Thank you for your time,

Mike Mitchell

0 Kudos
Reply

1,357 Views
mjbcswitzerland
Specialist V

Mike

Give it a few days and if you don't have success with modifying the MCUXpresso examples contact me for access to the uTasker project. I can do this with the following code on the FRDM-KL27Z (in KDS):

QUEUE_HANDLE newSerialID;
PWM_INTERRUPT_SETUP pwm_setup;
unsigned char ucInputBuffer[128];
QUEUE_TRANSFER inputLength;

// Configure and open LPUART
//
TTYTABLE tInterfaceParameters;                                   // table for passing information to driver
tInterfaceParameters.Channel = 0;                                // set UPUART channel for serial use
tInterfaceParameters.ucSpeed = SERIAL_BAUD_115200;               // baud rate
tInterfaceParameters.Config = (CHAR_8 | NO_PARITY | ONE_STOP | USE_XON_OFF | CHAR_MODE | UART_INVERT_TX);
tInterfaceParameters.Rx_tx_sizes.RxQueueSize = 64;               // input buffer size
tInterfaceParameters.Rx_tx_sizes.TxQueueSize = 512;              // output buffer size
tInterfaceParameters.Task_to_wake = OWN_TASK;                    // wake self when messages have been received
//tInterfaceParameters.ucDMAConfig = UART_TX_DMA;                // enable to run in DMA mode rather than interupt driven mode
SerialID = fnOpen(TYPE_TTY, FOR_I_O, ptrInterfaceParameters);    // open the channel with defined configurations (initially inactive)
fnDriver(SerialID, (TX_ON | RX_ON), 0);                          // enable rx and tx

// Configure a 1MHz PWM signal on the LPUART0 Tx output
//
pwm_setup.int_type = PWM_INTERRUPT;
pwm_setup.pwm_mode = (PWM_SYS_CLK | PWM_PRESCALER_16 | PWM_EDGE_ALIGNED); // clock PWM timer from the system clock with /16 pre-scaler
pwm_setup.int_handler = 0;                                       // no user interrupt call-back on PWM cycle
pwm_setup.pwm_frequency = PWM_FREQUENCY(1000000, 16);            // generate 1MHz on PWM output
pwm_setup.pwm_reference = (_TIMER_2 | 0);                        // use TPM2 channel 0
pwm_setup.pwm_mode |= (PWM_OPTION_MODULATE_LPUART0);             // modulate LPUART0 output with the PWM signal (possible on TPM1-CH0 or TPM2-CH0)
pwm_setup.pwm_value = _PWM_TENTH_PERCENT(706, pwm_setup.pwm_frequency); // 70.6% PWM (low/high) on different channel

// Send a message
//
fnWrite(SerialID, "Hello, World!!", 14);

// Receive messages and echo them back
//
while (inputLength = fnRead(SerialID, ucInputBuffer, sizeof(ucInputBuffer))) { // while there is reception
    fnWrite(SerialID, ucInputBuffer, inputLength);                // echo reception back
}

This configures the LPUART (change the channel to 1 to 2 for LPUART1 or UART2 instead of LPUART0) with the specified settings. Note that I invert the LPUART output for modulation mode (option). To use DMA the optional UART_TX_DMA is set.

Then a TPM is configured to modulate the LPUART Tx at 1MHz (70%) - TPM2 channel 0. The frequency, mark-space-ratio or other TPM/channels can be configured by changing the values (or other LPUARTs modulated).

Then I show sending data out, plus receiving data (and echoing it back).

That is all that is needed so I don't think that it can be done much simpler (with this flexibility).

I also attach a FRDM-KL27Z binary that shows this in operation on LPUART0 (the one connected to the VCOM). If you type something in it will echo it (and the modulated signal can be measured on J26). In addition I put a USB-CDC interface on the USB with a command line menu to allow debugging and various other monitoring/tests. In the uTasker project adding the USB-CDC command line interface costs just three lines of code effort for the programmer:
#define USB_INTERFACE
#define USB_DEVICE_SUPPORT
#define USE_USB_CDC
(and optionally #define USB_CDC_COUNT             2 [1..6 possible] for multiple USB-CDC connections at the same time).

A further advantage is that if you want to do the same thing on other Kinetis parts or boards you don't need to set up different projects and use different libraries and interfaces - you can just select the board (eg. FRDM_K64F instead of FRDM_KL27Z) and it already works there instead.
I don't think it can be much simpler than this....

Regards

Mark

0 Kudos
Reply

1,357 Views
mjbcswitzerland
Specialist V

Hi Mike

I expect there will be an example in the MCUXpressor configurator for your board.

Otherwise you can get a LPUART driver for the KL27 from the free open source uTasker project on Github (which is then compatible with all LPUART and UARTs in all Kinetis parts, so needs no porting in the future if you use different chips).

For professional use try the supported uTasker version that includes industrial proven LPUARTs in interrupt and DMA (also for free running reception), along with Modbus ASCII/RTU on any one, plus multiple USB<->LPUART bridges. Either native operation or FreeRTOS project operation out-of-the-box.

Both support KL27 simulation (including of UARTs in interrupt or DMA mode) for faster project development or analysis of internal workings.

Regards

Mark

Kinetis: http://www.utasker.com/kinetis.html
Kinetis KL25, KL26, KL27, KL28, KL82, KL43, KL46
- http://http://www.utasker.com/kinetis/FRDM-KL25Z.html
- http://www.utasker.com/kinetis/TWR-KL25Z48M.html
- http://www.utasker.com/kinetis/FRDM-KL26Z.html
- http://www.utasker.com/kinetis/TEENSY_LC.html
- http://www.utasker.com/kinetis/FRDM-KL27Z.html
- http://www.utasker.com/kinetis/Capuccino-KL27.html
- http://www.utasker.com/kinetis/FRDM-KL28Z.html
- http://www.utasker.com/kinetis/FRDM-KL82Z.html
- http://www.utasker.com/kinetis/FRDM-KL43Z.html
- http://www.utasker.com/kinetis/TWR-KL43Z48M.html
- http://www.utasker.com/kinetis/FRDM-KL46Z.html
- http://www.utasker.com/kinetis/TWR-KL46Z48M.html

For less questions and faster, cheaper developments: try uTasker for Kinetis

0 Kudos
Reply