Help trying to get CAN BUS connectivity working

This forum is for the discussion of other projects on Megasquirt/Microsquirt hardware that don't fit into any of the other forums

Moderators: jsmcortina, muythaibxr

Post Reply
alfaJunior105
Helpful MS/Extra'er
Posts: 57
Joined: Fri Jan 25, 2013 4:29 am
Location: Greenvale , Australia

Help trying to get CAN BUS connectivity working

Post by alfaJunior105 »

Hi

I’m trying to get CAN communication going between an Arduino and MS3 using an MCP2525 board.
I searched the forums and found bits and pieces that I were helpful, but I’m still missing something fundamental because I can’t even get basic communication working.
Most likely it’s something right under my nose – but I just can’t see it.

• I’m testing with the Stim, I have the MCP2525 CANL hooked up to pin4 and CANH on Pin3 of the Stim.
• I have the JR6 and JR8 jumpers wired on the board.
• I loaded Firmware 1.4
• In Tuner studio, I set ‘CAN Broadcasting’ and ‘RPM & Coolant’ on.

I cobbled together some very basic code to connect the Arduino to the MS and read a broadcast message.
At this stage I don’t care what ‘gobbly kook’ comes out, as long as I get something, later I can then look at the protocol and workout how to unpack the data into something I can use.
I’m pretty sure the MCP2525 board isn’t faulty because in the Setup function it initializes the CAN Shield successfully.

Below is Arduino code , the CAN.readMsgBuf in the main Loop never gets executed, i.e. no message received from MS3.
attached is the MSQ file too.

Any help would be appreciated
Sam

#include <mcp_can.h>
#include <SPI.h>
MCP_CAN CAN(9); // Set CS pin
unsigned char len = 0;
unsigned char buf[8];
//===============================================================================
//
//===============================================================================
void setup()
{
Serial.begin(115200);
while(1)
{
if (CAN_OK == CAN.begin(CAN_500KBPS)) // init can bus : baudrate = 500k
{
Serial.print("CAN BUS Shield init ok!");
break;
}
else
{
Serial.println("CAN BUS Shield init fail");
Serial.println("Init CAN BUS Shield again");
delay(1000);
}
}
}
//===============================================================================
//
//===============================================================================
void loop()
{
if(CAN_MSGAVAIL == CAN.checkReceive())
{
CAN.readMsgBuf(&len, buf);
Serial.print(" buf ");
Serial.println(CAN.getCanId());
}
}
Last edited by alfaJunior105 on Sat Feb 06, 2016 6:34 pm, edited 1 time in total.
MS3 v3board
V1.4.0 firmware, ITB Mode, Batch injection
4 gsxr750 Throttle bodies
14point7 AFR controller
EDIS4 ignition
grom_e30
Super MS/Extra'er
Posts: 4459
Joined: Thu Mar 08, 2012 12:44 pm
Location: UK

Re: Help trying to get CAN BUS connectivity working

Post by grom_e30 »

What is the can bus device you using? What speed crystal is on it?
1990 bmw 320i daily driver with m20b25 ms3 sequential fuel, 380cc injectors, d585 coil near plug, home made cam sync, launch control, fan control, vss, homebrew egt logging what's next????
Raymond_B
Super MS/Extra'er
Posts: 1398
Joined: Thu Mar 06, 2014 2:17 pm
Location: Texas
Contact:

Re: Help trying to get CAN BUS connectivity working

Post by Raymond_B »

Noob question, what does " pin4 and CANH on Pin3 of the Stim" mean? What is stim? Your stimulator? Why wouldn't you have CANH and CANL of MS to CANH and CANL of your transceiver? Once that is done, then you have to output Rx and Tx from transceiver to the device you want to output the data.

So;

MS ---------CANH -------- Transciever --------- Tx ------- Tx Microcontroller
MS ---------CANL -------- Transceiver ---------- Rx ------- Rx Microcontroller

I just went through this with a Teensy and the incorrect ASSumption that the Teensy had a transceiver. Once I added a Waveshare transceiver all was good. I am using a JimStim. Saga is here http://www.msextra.com/forums/viewtopic ... 23&t=61323
1995 Ford Lightning. Dart based 427 Windsor, Novi 2000, full sequential, E-85, etc. MS3X/v3.57
http://www.buildpics.org/
alfaJunior105
Helpful MS/Extra'er
Posts: 57
Joined: Fri Jan 25, 2013 4:29 am
Location: Greenvale , Australia

Re: Help trying to get CAN BUS connectivity working

Post by alfaJunior105 »

Hi thanks fro your resposnes.
I need to check

In response to the question from grom_e30
* The device is a MCP2515 CAN bus module with a TJA1050 receiver
* CAN V2.0B - communication speed 1Mb / S
* DC5V power supply module & SPI interface protocol control
* 120 ohm termination resistors, Impedance matching, ensure drive capacity, long-distance data transmission against signal radiation
* Here is a link to one on ebay formore details. http://www.ebay.com.au/itm/MCP2515-CAN- ... Swo0JWPJaK


In response to Raymond_B
The MS is off my car at the moment and for the purpose of getting this working , its sitting on my bench, hence the Stim is - simulating the car.
So my understanding and hence what I've done so far is.
* On the MS3 Jumpers 6 & 8 need to be wired to the SPR1 and 2 (respective) This equates (and connects) to pins 3 & 4 on the DB connector. the Stim plugs into that connector.
* The 2 pins being CANH & L are then connected to the MCPMCP2515
* in Tuner Studio you have to tell MS3 to broadcast messages onto the bus.

What I'm trying to do it poll for those messages.
So far I cant even see the messages and that's what I need help with - what am i doing wrong .


So going back to my original questions - Can anyone help me with why this'?
MS3 v3board
V1.4.0 firmware, ITB Mode, Batch injection
4 gsxr750 Throttle bodies
14point7 AFR controller
EDIS4 ignition
grom_e30
Super MS/Extra'er
Posts: 4459
Joined: Thu Mar 08, 2012 12:44 pm
Location: UK

Re: Help trying to get CAN BUS connectivity working

Post by grom_e30 »

Try setting the can bus speed to 1000kbps on the arduino. im using the same device and its got a 8mhz crystal in it but the librarys are designed for a 16mhz crystal. Swapping to a 16mhz crystal and setting to 500kbps works also
1990 bmw 320i daily driver with m20b25 ms3 sequential fuel, 380cc injectors, d585 coil near plug, home made cam sync, launch control, fan control, vss, homebrew egt logging what's next????
alfaJunior105
Helpful MS/Extra'er
Posts: 57
Joined: Fri Jan 25, 2013 4:29 am
Location: Greenvale , Australia

Re: Help trying to get CAN BUS connectivity working

Post by alfaJunior105 »

...
it lives !!!!!

grom_e30, your a superstar !

changing the speed to 1000kbps means I now get a message from the MS3.
Next step is to understand and begin pulling apart the message to actually do something with it :-)

thanks
Sam
MS3 v3board
V1.4.0 firmware, ITB Mode, Batch injection
4 gsxr750 Throttle bodies
14point7 AFR controller
EDIS4 ignition
grom_e30
Super MS/Extra'er
Posts: 4459
Joined: Thu Mar 08, 2012 12:44 pm
Location: UK

Re: Help trying to get CAN BUS connectivity working

Post by grom_e30 »

yeah it took me a while before i stumbled across that one, with the real time data or dash broadcasting it makes it so easy for you to grab the data you want http://www.msextra.com/doc/pdf/Megasqui ... -01-20.pdf will give you all the info on what info is where and how to scale it to a usable number.
1990 bmw 320i daily driver with m20b25 ms3 sequential fuel, 380cc injectors, d585 coil near plug, home made cam sync, launch control, fan control, vss, homebrew egt logging what's next????
Post Reply