FlexCase

CAN Guide

  • Send and receive CAN messages.
 

This guide requires that you have an independent piece of hardware capable of reading and writing to the CAN bus. See the CAN hardware section for more information.

Prerequisites

  • Complete the quick-start guide for a tutorial on connecting and flashing binaries
  • Complete the Simulink guide for building a model into a flashable binary
  • Download the latest Simulink sample software (we will use CAN.slx)

Connect to CAN Hardware

In order to confirm that your controller is communicating on the CAN bus, you will need an independent device capable of receiving and transmitting CAN messages. This generally includes a hardware converter with supported software.

  • For basic receiving and transmitting of standard message formats, many consumer-grade USB-to-CAN converters can be purchased for less than $50, with varying degrees of software support.
    • This type of interface can be purchased from various sources, and provides basic functionality for hardware and software.
    • CANable is an open source design that interfaces with various free software packages.
  • A more advanced module is recommended if you are integrating with an existing vehicle, requiring full bus debugging, logging, and other advanced features.
    • The PCAN-USB is relatively inexpensive and very widely supported by various software, and has various useful accompanying software tools.
    • The Kvaser USB interfaces provide several advanced functions with high capacity, and fully supported free software modules.
    • Vector has a variety of premium CAN trace tools and software. These tools are expensive but usually have large discounts for research use.

If you are unsure which type of hardware is appropriate for your application, please contact us for additional advice.

Connect CAN_H to C1-A1 and CAN_L to C1-B1 on the FlexCase.

Software Sample

Open CAN.slx and build the model. Flash the compiled software.

  • The FlexCase should immediately start sending the messages with ID 0x333 and 0x444 every 10ms
  • Start sending messages 0x111 and 0x222 from additional CAN hardware
  • The FlexCase should respond by summing/subtracting the values in the first byte of the received messages, and sending the results back on the 0x333 and 0x444 messages

Additional Info

The default settings for the FlexCase are to run the CAN0 bus at 500 kBaud (high speed CAN), and is capable of CANFD. The second bus CAN1 can be used if your FlexCase is communicating on two different busses or needs to integrated with sensors working on multiple baud rates.

The IDs and data payloads are arbitrarily chosen for this simple example. The send and receive blocks can be configured to communicate with the CANOpen, J1939, or other high-level CAN protocols.

If you have a DBC file for your application, you can use the Vehicle Network Toolbox to automatically pack and unpack CAN signals based on the DBC. This toolbox has additional support for many CAN devices.

Currently, PCAN is the only device that supports flashing the FlexCase software over CAN (see link for more info).