Megasquirt 3 - CAN communications

Back to index

Intro - Wiring - Configuration

What is CAN?

CAN is a two wire in-vehicle communications system that allows different vehicle computers to "talk" to each other.

Megasquirt 3 comes with CAN and allows it to communication with other CAN enabled devices such as Megasquirt-2, Microsquirt, the Sequencer, GPIO and likely other add-on boards.

Why use CAN?

The main benefits of using CAN are:

  • Tune multiple Megasquirt devices concurrently with your computer plugged in to one.
  • Multiple Megasquirt devices can share sensor and other data over the CAN network.
  • Connect more sensor inputs or control outputs than the base hardware supports
  • Simple connection. Just connect the two wires.

    What it does

    The Megasquirt implementation of CAN works on the industry standard hardware but is a specific implementation so will be unlikely to interconnect with CAN devices from other manufacturers. (If you have a specific request ask the developers.)

    The MegaSquirt® EFI Controller's implementation of CAN allows up to 14 auxiliary boards to be attached in a network, with each board having a unique address from 1 to 14. Typically address 0 is used for the master device.

    There are two main ways that CAN is used in a Megasquirt system : CAN-passthrough and device-to-device CAN.

    1. CAN-passthrough

    In this mode messages from your tuning computer are relayed to remote devices over the CAN network.

    e.g. tuning the remote device from your laptop.

    This can really useful when you have more than one Megasquirt device on your vehicle, with a single connection point for your tuning computer you can "connect" to any of the devices on the network and view data, tune etc. You could also use the computer to datalog from multiple devices concurrently. The logging speed will be reduced the more devices you try to log from.

    TunerStudio allows a project to be created that will allows you to view and tune multiple CAN devices concurrently. However, you should consider carefully if this is right for your application. Frequently it will be sufficient to setup the remote device once and then configure the MS3 to fetch data using device2device CAN. This will usually result in faster logging times and is easier to understand.

    How CAN-passthrough works

    The tuning computer is connected to the Megasquirt-3 either by serial or USB-serial.
    The Megasquirt-3 and remote device are connected by the two wires of CAN.

    Step 1.
    Tuning computer sends USB/serial request to Megasquirt (addressed to remote device.)

    Step 2.
    Megasquirt 3 recognises this as a passthrough request and relays it on to the remote device over CAN

    Step 3.
    Remote device answers request and sends back data over CAN.

    Step 4.
    Megasquirt 3 receives data and forwards it on to tuning computer by USB/serial.



    2. Device to device CAN communication

    In this mode two devices on the CAN network exhange data independant of the tuning computer.

    e.g. A transmission controller fetching engine data from the Megasquirt3, or the Megasquirt 3 polling devices on the network and datalogging the results.

    Once configured the data transmission will happen as and when required with no user intervention.





    The two devices request data and receive data on their own, independent of any tuning computer



    See here for instructions on configuring a remote MS2 card to enable analogue data capture to the MS3.

    How it is wired

    General layout

    Example of MS3 and Microsquirt

    Key points to note.

    Configuration

    Having wired in your devices in the previous section, the devices need some configuration before they will "talk" to each other.

    CAN settings within MS3

    MS3 CAN settings dialogue

    Base data
    My CAN ID - the CAN ID of this MS3 - normally left at zero.

    PWM polling
    The MS3 can collect remote PWM type input data, from a VSS for example.
    Sample data when using the GPIO board is shown in []
    Sample data when using the JBPERF MS2/Extra Extender is shown in ()

    Remote CAN ID - the CAN ID of the remote board
    Enable PWM polling - enable or disable this feature
    Remote table number for PWM data - [6] (7)
    Remote table offset for PWM data - varies per application. [39] (18)
    Remote clock - The clock on the remote device [?] (24)
    Remote prescale - If used a prescale divider [?] (16)
    Remote divider - If used a clock divider [?] (3)

    Digital ports
    This allows the MS3 to use up to eight remote on/off inputs (CANIN1-8) and up to sixteen remote on/off outputs (CANOUT1-16).
    CANIN1 is bit 0 from the remote input port and CANIN8 is bit7.
    CANOUT1 is bit 0 from the first remote output port and CANOUT8 is bit7.
    CANOUT9 is bit 0 from the second remote output port and CANIN16 is bit7.

    Remote CAN Id - the remote CANid to fetch from [1] (5)
    Table - the remote table number [2] (7)
    Enable input port - enable remote input port
    Offset - the offset number in the remote table [?] (*)
    Enable output port - enable remote output port
    Offset - the offset number in the remote table [?] (*)

    PWM outputs
    This allows PWM outputs on a remote CAN device.
    Not yet supported

    ADC polling
    This allows additional analogue inputs to be captured from remote CAN devices and used with most MS3 features. The code allows up to 24 remote CAN ADCs. The dropdown menus (e.g. EGT) allow you to select either a local ADC or a remote CANADC. Before attempting to use the chosen CANADC you need to enable it on this CAN settings menu.
    Due to data sizes, the CANADCs are configured in groups of four. The exact table and offset numbers are specific to the configuration of the remote device. The example data shown in the screen shot above is suitable for use with the JBPERF Extender.

    Enable ADC polling - enable or disable the feature
    CAN ADC 1-4 - enable or disable this group.
    CAN Id - the remote CANid to fetch from
    Table - the remote table number
    Offset - the offset number in the remote table

    Using the GPIO board
    The GPIO from Bowling and Grippo makes use of the Megasquirt CAN system and allows the MS3 to collect the data from the GPIO inputs. The GPIO has up to:
    8 general or thermistor inputs. 4 of these may be used for thermocouple EGT inputs

    Refer to the GPIO site for intial configuration. Once you have wired and set up the device, you need to configure the MS3 to use the data. This is working in device2device mode.

    MS3 settings with GPIO
    CAN device = 1
    Table = 6
    The four ADC inputs are shown here assigned to CANADC1-8 but other CANADCs can be used.
    GPIO ADCFunctionMS3 CANADCOffset
    ADC0-3general ADC inputsCANADC1-4??
    ADC4-7general ADC inputsCANADC5-8??

    Using the JBPERF Extender
    The Extender from JBPERF makes use of the Megasquirt CAN system and allows the MS3 to collect the data from the Extender's inputs. The Extender has up to:
    8 general or thermistor inputs
    8 thermocouple EGT inputs
    3 axis accelerometer
    Realtime clock (not yet used with MS3)
    Global Positioning System (not yet used with MS3)

    Refer to the Extender documentation on the JBPERF site for intial configuration. Once you have wired and set up the device, you need to configure the MS3 to use the data. This is working in device2device mode.

    MS3 settings with Extender
    ADCs
    CAN device = 5
    Table = 7
    Extender ADCFunctionMS3 CANADCOffset
    ADC0-3general ADC inputsCANADC1-42
    ADC4-7general ADC inputsCANADC5-810
    ADC8-11EGT inputsCANADC9-1218
    ADC12-15EGT inputsCANADC13-1626
    ADC16-19Battv, accelerometer inputsCANADC17-2034
    ADC20-233v3 ref, general ADC inputsCANADC21-2442

    NOTE: Be sure to set the Extender to 10bit ADC for compatability with MS3.

    Digital ports
    If you wished to configure ports 1 and 2 as digital output ports (16 channels) and port 3 as a digital input with the following settings.
    Remote CAN Id5
    Table7
    Enable input portEnable
    Offset77
    Enable output portTwo
    Offset75

    CAN settings for other devices in the CAN network

    The first and most critical step is that all devices need to have a unique CAN address. Typically the box you plug in to will be 0, this is the standard setting so you can leave it alone.

    This first time, you may need to plug your computer in to each remote device in turn and set its CAN id. Once you have changed the CANid of the device you will temporarily lose communications with it until you reconfigure your tuning software with the matching new CANid - this is normal.

    See here for instructions on configuring a remote MS2 card to enable analogue data capture to the MS3.

    If you change the CANid of a device, you will need to update the Project Properties in TunerStudio to reflect this change. This feature is presently in development - this page will be updated with screenshots when it is complete

    TunerStudio allows you to tune multiple devices simultaneously with a combination of gauges on the dashboard.

    (This section will be expanded with some worked examples)

    There is a more technical description of the CAN infrastructure here - CAN technical


    MegaSquirt® and MicroSquirt® controllers are experimental devices intended for educational purposes.
    MegaSquirt
    ® and MicroSquirt® controllers are not for sale or use on pollution controlled vehicles. Check the laws that apply in your locality to determine if using a MegaSquirt® or MicroSquirt® controller is legal for your application.


    ©2005, 2007, 2009 Bruce Bowling, Al Grippo and James Murray. All rights reserved. MegaSquirt® and MicroSquirt® are registered trademarks.