MCUXpresso SDK Documentation

canfd_interrupt_transfer_low_level

canfd_interrupt_transfer_low_level#

Overview#

The canfd_interrupt_transfer_low_level example shows how to use FlexCAN driver in non-blocking interrupt way using low-level hardware APIs:

This example is similar to flexcan_interrupt_transfer but uses low-level hardware APIs instead of the transfer layer:

  • Does NOT use flexcan_handle_t or FLEXCAN_TransferCreateHandle()

  • Does NOT use FLEXCAN_TransferFDSendNonBlocking() / FLEXCAN_TransferFDReceiveNonBlocking()

  • Uses direct hardware APIs: FLEXCAN_WriteFDTxMb(), FLEXCAN_ReadFDRxMb(), FLEXCAN_GetMbStatusFlags(), FLEXCAN_ClearMbStatusFlags()

  • ISR directly handles interrupts without transfer layer callback mechanism

In this example, two FlexCAN instances on a single board communicate with each other:

  • FlexCAN_RX is configured as receiver

  • FlexCAN_TX is configured as transmitter

  • When user presses any key in the terminal, FlexCAN_TX sends a CAN message to FlexCAN_RX

  • FlexCAN_RX receives the message and prints the content to the terminal

  • The data byte is incremented for each transmission

This design demonstrates one-way communication between two FlexCAN peripherals on the same board using low-level interrupt-driven APIs.

Supported Boards#

FRDM-MCXE31B
Hardware requirements
  • Micro USB cable

  • FRDM-MCXE31B Board

  • Personal Computer

Board settings

This example uses two FlexCAN instances (FlexCAN0 and FlexCAN1) on a single board for internal communication. The two CAN instances must be connected externally:

       FlexCAN0         connect to      FlexCAN1
Pin Name   Board Location         Pin Name    Board Location
CANH       J17-1                  CANH        J18-1
CANL       J17-2                  CANL        J18-2

Note: Verify the correct FlexCAN0 and FlexCAN1 pin locations on FRDM-MCXE31B board schematic.

Prepare the Demo
  1. Connect the CAN buses between FlexCAN0 and FlexCAN1 as shown above.

  2. Connect a type-c USB cable between the host PC and the MCU-Link USB port (J13) on the target board.

  3. Open a serial terminal with the following settings:

    • 115200 baud rate

    • 8 data bits

    • No parity

    • One stop bit

    • No flow control

  4. Download the program to the target board.

  5. Either press the reset button on your board or launch the debugger in your IDE to begin running the demo.

Running the demo

When the example runs successfully, the following message is displayed in the terminal:

********* FLEXCAN Interrupt (Low-Level) EXAMPLE *********
    Message format: Standard (11 bit id)
    FlexCAN_RX: Receiver (Message buffer 1)
    FlexCAN_TX: Transmitter (Message buffer 0)
    Interrupt Mode: Enabled (Low-Level API)
    Operation Mode: One-way communication
**********************************************************

Initializing FlexCAN_RX as receiver...
Initializing FlexCAN_TX as transmitter...

Press any key to trigger transmission from FlexCAN_TX to FlexCAN_RX

FlexCAN_TX: Transmitted frame with data 0x 0
FlexCAN_RX: Received frame - ID: 0x123, Data: 0x 0, Timestamp: 59456
Press any key to trigger the next transmission!

FlexCAN_TX: Transmitted frame with data 0x 1
FlexCAN_RX: Received frame - ID: 0x123, Data: 0x 1, Timestamp: 1339
Press any key to trigger the next transmission!

FlexCAN_TX: Transmitted frame with data 0x 2
FlexCAN_RX: Received frame - ID: 0x123, Data: 0x 2, Timestamp: 15741
Press any key to trigger the next transmission!