Hi All,
I have an Arduino Mega, and a Sparkfun Canbus shield, and I’m trying to read data from my Syvecs ECU (not OBD-II per se).
I am using the Canbusv4 library.
I have found all the info regarding changing the pin assignments for the Arduino Mega, and think I have got that part working OK, but am still having issues reading/writing CAN data.
This is my modification to the defaults.h file:
#ifndef DEFAULTS_H
#define DEFAULTS_H
#define P_MOSI B,2 // pin 51
#define P_MISO B,3 // pin 50
#define P_SCK B,1 // pin 52
#define MCP2515_CS B,0 // pin 53
//#define MCP2515_INT E,4 // pin 2
#define MCP2515_INT D,2 //Pin 19
#define LED2_HIGH H,5 // pin 8
#define LED2_LOW H,5 // pin 8
#endif // DEFAULTS_H
With no CAN-H or CAN-L cables connected to the shield, I can get the ‘CAN Init OK’ message, but only when running with 1000kbps baud rate. I’m achieving this using the following line in Canbus.h:
#define CANSPEED_1000 0
I have tried connecting my DSO scope to the CAN lines whilst repeatedly sending CAN messages using the code below, but I see no change through the scope:
#include <Canbus.h>
#include <defaults.h>
#include <global.h>
#include <mcp2515.h>
#include <mcp2515_defs.h>
#include <SPI.h>
char buffer[512]; //Data will be temporarily stored to this buffer before being written to the file
int read_size=0; //Used as an indicator for how many characters are read from the file
int count=0; //Miscellaneous variable
void setup() {
Serial.begin(115200);
Serial.println("ECU Reader"); /* For debug use */
if(Canbus.init(CANSPEED_1000)) /* Initialise MCP2515 CAN controller at the specified speed */
{
Serial.println("CAN Init ok");
} else
{
Serial.println("Can't init CAN");
}
delay(2000);
}
void loop()
{
tCAN message;
message.id = 0x631; //formatted in HEX
message.header.rtr = 0;
message.header.length = 8; //formatted in DEC
message.data[0] = 0x40;
message.data[1] = 0x05;
message.data[2] = 0x30;
message.data[3] = 0xFF; //formatted in HEX
message.data[4] = 0x00;
message.data[5] = 0x40;
message.data[6] = 0x00;
message.data[7] = 0x00;
mcp2515_bit_modify(CANCTRL, (1<<REQOP2)|(1<<REQOP1)|(1<<REQOP0), 0);
mcp2515_send_message(&message);
}
Can anyone help me please? I’m tearing my hair out!!
Specific questions:
-
When the CAN Bus initialises, is that simply reporting the SPI connection between the Arduino and the Shield had been successful?
-
I’ve read lots about Baud rate, bit rate, and bit timing. I know my ECU CAN runs at 1Mbps, and I know the Frame identifiers. Is bit timing likely to affect messages being ‘scopeable’? I can’t see how it would?!
-
Does the Sparkfun shield have a 120ohm terminating resistor built in?
Sorry for my first noob post. Hope someone can help!!