UART Rx to CAN

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

UART Rx to CAN

854 Views
nakulyadur
Contributor III

Hello,

I am using MK22FX512VLH12 MCU and a sensor is connected to the MCU. I am receiving sensor data on the UART and I want to send the UART Frame to CAN on the same MCU. How can I send the data that I am receiving on UART RX to the CAN on the same MCU? How can I mask the data? Any help is appretiated. Thanks.

best regards,

Nakul

Labels (1)
0 Kudos
3 Replies

585 Views
isaacavila
NXP Employee
NXP Employee

Hello Nakul,

Basically, you need to read data from UART by reading UARTx_D register once UARTx_S1[RDRF] field has been set. You can use a simplest method of sending to CAN module every incoming data from UART in UART RX interrupt (or maybe you prefer to save this data into a global buffer, then read data from this buffer and send it through CAN)

UART module has capability to send/receive up to 9-bit data and you can also use FIFO functionality (Available for UART0 and UART1 only), but, supposing you are using basic 8-bit data transfers and no FIFO functionality, you can save received characters by using Receiver Full Interrupt (UARTx_C2[RIE]), for example, interrupt routine should look like this (if using baremetal implementation):

void UART0_RX_TX_IRQHandler (void) {

    /* RX data received ? */

    if (UART0_S1 & UART_S1_RDRF_MASK) {

        if (g_write_ptr > (RX_BUFFER_SIZE - 1)) {

            /* Point to start buffer */

            g_write_ptr = g_rx_buffer;

        }

        /* Save data into buffer */

        *g_write_ptr++ = UART0_D;

    }

}

So, in every UART RX interrupt, data from UART module will be saved in g_rx_buffer buffer (Be aware to enable UART interrupt in NVIC module as well).

Once you have available data ready to be sent (you will also need to add extra logic to handle next data to be read), you will need to follow transmit process that is shown in section 46.4.1 Transmit process from MK22's reference manual.

If you are using Kinetis SDK you can look to flexcan_network_example_twrk21f120m example that is located at: <KSD_1_3_PATH>\examples\twrk21f120m\driver_examples\flexcan\flexcan_network\ or this same example for KSDK 2.0: <SDK_2.0_MK22FX512xxx12>\boards\twrk21f120m\driver_examples\flexcan

Hope this can help you!

Best Regards,

Isaac

0 Kudos

585 Views
nakulyadur
Contributor III

Hello Isaac,

Thanks for the reply.

I am using Processor expert and I am trying to send 10 bit data from UART to CAN module.

How do I set the incoming data on UART to send directly to CAN?

Do you have any example programs of sending data from UART to CAN directly or saving it globally and sending it?

Thanks.

best regards,

Nakul

0 Kudos

585 Views
isaacavila
NXP Employee
NXP Employee

Hello Nakul,

The previous example does use UART and CAN and could guide you to implement what you want, please, check KSDK 1.3 or KSDK 2.0 example (KSDK 1.3 does support Processor Expert).

Hope this can help you!

Regards,

Isaac

0 Kudos