NetBurner 3.5.8
PDF Version
CAN FD Send and Receive

Example Path: examples/PlatformSpecific/MODRT1171/CAN/CanFdSimple

Overview

This example turns the MODRT1171 into an interactive CAN FD node on FlexCAN1, the module's primary CAN bus. CAN FD (Flexible Data-rate) extends classic CAN with payloads up to 64 bytes per frame and, with bit-rate switching (BRS), a data phase that runs faster than the arbitration phase. This node arbitrates at 500 kbit/s and switches to 2 Mbit/s for the data phase of BRS frames.

A receive task prints every frame seen on the bus – classic or FD – with the FD flags decoded (EDL = FD frame, BRS = bit-rate switch, ESI = error state indicator), and a serial menu sends classic frames, FD frames with BRS, and FD frames without BRS, so you can watch each variant on a bus analyzer or a second node.

An FD node receives and transmits classic frames as well – one FD message buffer carries both types – so this example doubles as a general bus monitor. Every node on a bus carrying FD frames should be FD-capable.

The FlexCAN driver (fsl_flexcan, NXP SDK version 2.11.6) is built into the NetBurner MODRT1171 platform library; the example includes <fsl_flexcan.h> directly and bundles no driver source.

Hardware requirements

  • MODRT1171 module
  • CAN FD capable 3.3 V transceiver (MCP2562FD, TJA1051T or similar – it must support the 2 Mbit/s data phase) wired to the FlexCAN1 pins
  • A second FD-capable CAN node – another MODRT1171 running this example, a USB CAN-FD adapter on a PC, or any other node – configured for 500 kbit/s arbitration / 2 Mbit/s data
  • Personal Computer
  • Serial terminal program connected to the MODRT1171 UART0 serial port

Board settings

Wire the FlexCAN1 signals to your transceiver's TXD/RXD pins:

Signal Module pin (rev 1.5) Transceiver pin
FlexCAN1 RX P1.26 RXD
FlexCAN1 TX P1.27 TXD

Connect the transceiver's CANH/CANL to the bus, and remember the 120 ohm termination resistors at both ends of the bus.

Note
This example is written for the MODRT1171 rev 1.5 module. At rev 1.6 (which makes the module a MOD5441X drop-in replacement), the FlexCAN1 signals move from the P1 header to the P2 header: RX moves P1.26 -> P2.41 and TX moves P1.27 -> P2.44. The FlexCAN1 peripheral instance and this example's driver code are unchanged; only the two pin-function lines in UserMain() change with the module revision. Designs that need more than one CAN bus have options beyond FlexCAN1: FlexCAN3 is available on the I2C pins for designs that do not use I2C (or that bit-bang I2C on spare GPIO), and on rev 1.5 FlexCAN2 also reaches module pins – all three controllers support CAN FD. For pin details see the MODRT1171 Software Developer Guide and the MODRT1171 Pinout Update document: https://www.netburner.com/download/MODRT1171_Rev1p5_to_Rev1p6_Pinout_Update/

Running the demo

Build and load the application, then open the serial terminal:

CAN FD bus: FlexCAN1, 500 kbit/s arbitration / 2000 kbit/s data (BRS),
RX pin P1.26, TX pin P1.27
Menu:
S - send a classic 8-byte frame, ID 0x123
F - send a 64-byte CAN FD frame with BRS, ID 0x123
D - send a 64-byte CAN FD frame without BRS, ID 0x123
T - print the transmit / receive error counters
A - abort a pending (unacknowledged) transmission
Received frames print as they arrive.
void print(const char *str)
Write out a zero-terminated, unbuffered string.

Press 'S', 'F', or 'D' to transmit; frames from other nodes print as they arrive, with the frame type decoded:

Received classic ID 0x123 len 8 [50,49,4E,47,38,42,59,54,:PING8BYT]
Received FD+BRS ID 0x123 len 64 [4E,65,74,42,75,72,...:NetBurner MODRT1171 CAN FD...]

A CAN transmission is only complete once another node acknowledges it. If you press a send key with no transceiver or second node attached, the controller keeps retransmitting the frame, the transmit buffer stays busy, and further sends are refused with an explanatory message – press 'A' to abort the pending frame, and 'T' to watch the error counters. The CanErrorMonitor example explores the error states in depth.

To verify CAN FD operation on a single module with no external hardware – including a measured classic-vs-FD throughput comparison – run the CanFdLoopback example first. For the classic CAN version of this node, see CanSimple.