|
NetBurner 3.5.8
PDF Version |
Example Path: examples/PlatformSpecific/MODRT1171/CAN/CanSimple
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.
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.
Build and load the application, then open the serial terminal:
Press 'S' or 'E' to transmit; frames from other nodes print as they arrive:
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.