Hello, I am working on a small project using a Teensy 3.2 to read data via CAN from a Microsquirt engine control computer. http://www.msextra.com/manuals/ms3manuals/
I have a Teensy 3.2, running Arduino 1.6.7 on Windows 8. I've loaded the CANListen Sketch found on these forums. I have everything hooked up and it appears I am seeing data, however it seems to be the same data over and over until I power cycle the Megasquirt then the data changes, but only once and it goes back to the same stream. I have hooked up some of the inputs of the Megasquirt and changed their (things like throttle position, RPM, engine temp, etc.) values, with no change to the CAN data stream. The message idea appears correct, but again the data in serial monitor does not change. It seems as if the program simply grabs the first bit of data and loops it endlessly.
Example:
This repeats
ID: 0x5E8 DLC: 8 DATA: 0 5F 0 0 7 8 0 3
Power Cycle MS and this repeats until next powercycle.
ID: 0x5E8 DLC: 8 DATA: 0 6F 0 0 7 8 0 25
And so on.
For further information here is some documentation to the MS CAN protocol, this PDF details out the "Dash Broadcasting" feature which I am using. Simply put it is a smaller data set for things like DIY guages and displays. http://www.msextra.com/doc/pdf/Megasquirt_CAN_Broadcast.pdf
I have a Teensy 3.2, running Arduino 1.6.7 on Windows 8. I've loaded the CANListen Sketch found on these forums. I have everything hooked up and it appears I am seeing data, however it seems to be the same data over and over until I power cycle the Megasquirt then the data changes, but only once and it goes back to the same stream. I have hooked up some of the inputs of the Megasquirt and changed their (things like throttle position, RPM, engine temp, etc.) values, with no change to the CAN data stream. The message idea appears correct, but again the data in serial monitor does not change. It seems as if the program simply grabs the first bit of data and loops it endlessly.
Example:
This repeats
ID: 0x5E8 DLC: 8 DATA: 0 5F 0 0 7 8 0 3
Power Cycle MS and this repeats until next powercycle.
ID: 0x5E8 DLC: 8 DATA: 0 6F 0 0 7 8 0 25
And so on.
For further information here is some documentation to the MS CAN protocol, this PDF details out the "Dash Broadcasting" feature which I am using. Simply put it is a smaller data set for things like DIY guages and displays. http://www.msextra.com/doc/pdf/Megasquirt_CAN_Broadcast.pdf
Code:
// -------------------------------------------------------------
// CANlisten for Teensy 3.1
// by kjn
//
// This test enables the CAN interface on the teensy and prints all recieved packets
// to the serial console. The RX FIFO buffer may overrun at high bus utilisation
// states. This is untested.
#include <FlexCAN.h>
// Specify CAN Baudrate. Currently 125k, 250k, 500k, 1M are supported in teensydrino 1.20
int baud = 500000;
int led = 13;
FlexCAN CANbus(baud);
static CAN_message_t rxmsg;
void setup(void)
{
Serial.begin(9600);
while (!Serial) ; // wait for Arduino Serial Monitor
Serial.println("Teensy 3.1 CANlisten Example");
//boolean result = CANbus.begin(); -- Currently .begin object doesn't return state of bus
//Serial.print("CAN begin successful: ");
//Serial.println(result ? "YES" : "NO");
CANbus.begin();
//Light on to indicate on-bus state
pinMode(led, OUTPUT);
digitalWrite(led, 1);
}
void loop(void){
//Poll Rx FIFO
while ( CANbus.read(rxmsg) ) {
//when message available
//light off to indicate FIFO is not being polled
digitalWrite(led, 0);
//construct string
String text = "ID: 0x";
text = String(text + String(rxmsg.id, HEX));
text = String(text + " DLC: ");
text = String(text + String(rxmsg.len, HEX));
//check if DLC is >0 append string as required
if (rxmsg.len >= 1)
{
text = String(text + " DATA: ");
}
//construct string for available bytes (trunctate to DLC to avoid reading garbage)
for( int idx=0; idx<rxmsg.len; ++idx )
{
text = String(text + String(rxmsg.buf[idx],HEX));
text = String(text + " ");
}
//print result
Serial.println(text);
//LED back on to indicate watching Rx FIFO
digitalWrite(led, 1);
}
}