|
Megasquirt 3 - CAN communications |
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:
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.
Step 2.
Step 3.
Step 4.
|
|
||||
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.
CANH to CANH,
CANL to CANL
One 120 ohm termination
resistor at each end of the "bus" - this will almost
always be inside the box.
The Megasquirt 3 comes with the resistor
already in place, so no action is required.
Note that neither wire is connected to ground.
If your Megasquirt-3 is pre-assembled, ensure that the CAN connections are actually present inside the box.
Otherwise - complain to your vendor!
If you assembled the board yourself, then make sure that YOU installed the jumper wires.
On V3.0 and V3.57 boards you need the following jumpers
If you only have two devices connected then the "bus" will simply two wires running from one box to the other, as shown in the MS3/Microsquirt example diagram above.
If you are connecting three or more devices you WILL need to connect them as above and ensure only the two end devices have terminators and the middle ones do not.
For short runs of cable a simple pair of wires is likely ok, for large runs it may be advisable to use twisted pair or twin core screened cable.
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
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 ADC | Function | MS3 CANADC | Offset |
| ADC0-3 | general ADC inputs | CANADC1-4 | ?? |
| ADC4-7 | general ADC inputs | CANADC5-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 ADC | Function | MS3 CANADC | Offset |
| ADC0-3 | general ADC inputs | CANADC1-4 | 2 |
| ADC4-7 | general ADC inputs | CANADC5-8 | 10 |
| ADC8-11 | EGT inputs | CANADC9-12 | 18 |
| ADC12-15 | EGT inputs | CANADC13-16 | 26 |
| ADC16-19 | Battv, accelerometer inputs | CANADC17-20 | 34 |
| ADC20-23 | 3v3 ref, general ADC inputs | CANADC21-24 | 42 |
| Remote CAN Id | 5 |
| Table | 7 |
| Enable input port | Enable |
| Offset | 77 |
| Enable output port | Two |
| Offset | 75 |
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.