NetBurner 3.5.8
PDF Version
CAN Send and Receive

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

Overview

This example turns the MODRT1171 into an interactive CAN node on FlexCAN1, the module's primary CAN bus. A receive task prints every frame seen on the bus – ID, length, and payload in hex and ASCII – and a serial menu sends standard-ID and extended-ID frames on demand. It is the starting point for building your own CAN application on the module.

The receive message buffer is configured with an accept-all mask, so the example acts as a simple bus monitor: any standard (11-bit) or extended (29-bit) frame on the bus is printed as it arrives.

All transmissions use the FlexCAN driver's non-blocking transfer API, so the menu stays responsive even when no other node acknowledges the frames (for example, while your bus wiring is still in progress).

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

Hardware requirements

  • MODRT1171 module
  • 3.3 V CAN transceiver (SN65HVD230 or similar) wired to the FlexCAN1 pins
  • A second CAN node – another MODRT1171 running this example, a USB-CAN adapter on a PC, or any other node – configured for 500 kbit/s
  • 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. 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 bus: FlexCAN1 at 500 kbit/s, RX pin P1.26, TX pin P1.27
Menu:
S - send a standard frame, ID 0x123, payload "TEST"
E - send an extended frame, ID 0x1234, payload "ETEST"
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' or 'E' to transmit; frames from other nodes print as they arrive:

Received standard ID 0x123 len 4 [54,45,53,54,:TEST]
Received extended ID 0x1234 len 5 [45,54,45,53,54,:ETEST]

A CAN transmission is only complete once another node acknowledges it. If you press 'S' 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. Press 'T' to watch the transmit error counter (TEC) while this happens: each failed transmission raises it by 8, moving the controller through its error states. The CanErrorMonitor example explores these error states in depth.

To verify FlexCAN operation on a single module with no external hardware, run the FlexcanLoopback example first.