After reading many topics here, I still have a problem that has been reported several times but that is not being solved in my case.
I am developing a device to communicate with car dashboards in order to do some tests after repairs that are made. Like a car signal simulador to test the dashboard.
My equipment:
UNO+WiFi-R3-AT328-ESP8266-32MB-CH340G for PC conection
MCP 2515 with 8MHZ for CAN BUS interaction
These modules are connected in the usual way:
VCC – 5V from Arduino
GND – GND from Arduino
CS – D10 from Arduino
SO - D12 from Arduino
SI - D11 from Arduino
SCLK - D13 from Arduino
INT - D2 from Arduino
Without jumper on MPC2515
The dashboard is from a FIAT Punto (works at 500kb/s), is powered by a external 12v power supply and is monitored by an oscilloscope. So I am sure there is a signal at CAN low and CAN high after the key contact (+15).
These two CAN signals appear coherent and arrive at the MCP2515 module.
I installed several libraries, tested several files to read and write in CAN protocole but nothing worked.
I even installed a program called CANHacker, following all the requested steps to interact that with the MCP module… but nothing works.
I'm starting to question if the MPC2515 is not damaged. I tested the connection cables between modules and the connections on Pin…
In order to start at the right way, could anyone help with an up-to-date library and program that you know that works in order to troubleshooting where is the error?
I promise to put pictures of each step tried and explanations of what was done in order to be a kind of tutorial for those who have the same type of problem.
send one CAN message without connecting to a CAN bus
This will cause the CAN module to repeat the message over and over again because no node on the bus will acknowledge the message. This will give you time to look at the signal with your oscilloscope. You should see a nice differential signal with the same bit timing as your car.
Check to see if you have a 8 or 16MHz crystal on the MCP2515 board and do a loopback test to prove that the MCP2515 SPI communication to the Arduino works.
A) this is the FIAT Punto Dashboard
B) this is my UNO
C) this is my MCP2515 with osciloscope probes to test it.
D) this is the signal when the dashboard is not powered.
E) this is the signal when i power the dashboard in key contact (+15)
I put some annotations in the code to verify that this is what has to be done so that others with the same problem will also notice.
If there are other changes to be made for this specific case, please identify them.
to download mcp_can.h
to download SPI.h
I downloaded both libraries and didn't make any changes to them. Is it necessary to adjust any lines of code in them?
I ran the can loop procedure and I'll leave all the steps behind so I can help other people understand the procedure.
To check if MCP2515 is ok.
by steps:
1_ I copied the code text to the arduino software.
2_ I made the changes only in the code that I marked (16 for 8MHZ).
3_ I loaded the sketch onto my arduino with the USB cable on COM3 and with keys 3 and 4 turned ON to establish communication between the USB and ATMEGA.
4_ the sketch was successfully loaded onto the board.
5_ with the oscilloscope connected to the CANL and CANH ports, I see a different signal than when the board is off without the message. I don't know if these are the expected values but it displays these values from the image.
6_ with the serial monitor open, I see the following message in a loop:
Try the CAN_receive.ino and set the 8 MHz option. Make sure there is a ground wire linking the dashboard to the MCP2515 module.
If you get nothing try swapping the High and Low wires.
If that doesn't work then use the oscilloscope to measure the width of a single bit and use that to calculate the actual baud rate.
3_ connected the GND of the source that supply the dashboard in connection with the arduino that supply the MCP. So the GNDs are all connected.
4_ loaded the program to UNO with the same keys turned on (3 & 4) All ok with the loading.
5_ I turned on the power supply and the oscilloscope started to detect CAN communication measured on the MCP board.
6_ I opened the "serial monitor" with 115200baud, just like what was written on the sketch. The result is this (see the image): no communication appears.
7_ changed the CAN L & CAN H cables but it stayed the same. I am sure that the cables are right connected because I have the dashboard wireframe and the pin function.
8_ seeing the oscilloscope, I check the data I send in the image. It may not be 100% strict. I would like to know how to calculate the baud to confirm that 115200 value. If the measure of a single bit is the same in both CAN (High and Low), I think it's 4,5V = VPP??
9_ if the crystal in dashboard has not the same value, why we use 8MHZ?
10_ I read that this dashboard follows the FIAT CAN B protocol.
CAN B is a low speed protocol (125Kbps).
The signal follows the same pattern as the signal I get from the oscilloscope as you can see in the link:
Do I have to change the communication speed where it says 500kbps? Or elsewhere?
Please follow mikb55 advice and measure the CAN bitrate with your oscilloscope. Pick the narrowest bit. Measure the time and take the inverse to get the bitrate. e.g.,
20 µs -> 20 / 1,000,000 -> 0.00002 s -> 1bit / 0.00002 s = 50,000 kbit/s
Reply #5 E looks like 50-60 kbits/s CAN. It is hard to tell from the picture and the resolution.
Reply #10 looks like 50 kbits/s CAN.
A 16MHz crystal is the only one that allows all CAN standard baudrates to be created by the MCP2515 (and a few in between). The 8MHz allows all CAN standard baudrates up to 500kbits/s to be created.
But my question about the crystals is: in post #6 I published a photo with all the crystals of the 3 devices. they are not all the same value. Why not choose the crystal from dashboard (5MHZ) as the default value instead the crystal of MCP (8MHZ) ??
The dashboard CAN controller creates the CAN bitrate from the 5MHz crystal. This is done by the internal hardware and you do not need to worry about it. Only the 50kbits/s you measured are important.
Your MCP2515 needs to use 50kbits/s. To configure the MCP2515 correctly you will need to tell the library the frequency of the crystal. If you tell the library the wrong frequency the bitrate will be wrong. e.g., 16MHz vs 8MHz will cause 100kbits/s instead of the 50kbits/s.
The serial baudrate is independent from the CAN bitrate.
Sounds promising. Can you receive CAN messages now?
I understand but: if the dashboard crystal is the one that sends the message, and if the message is sent by a 5MHZ crystal at 50Kbps, how is the MCP crystal at 8MHZ also configured to read at 50Kbps?
Do you recommend any article that better explains this issue of frequencies versus transmission speed?
The crystal serves to receive and transmit right? So it could be transmiting messages at the same speed but with different frequency rates?
I already configured the code of the CAN_receive file and I leave here the comments of what I changed.
I just put the code in an image to make it easier to mark what I changed from the original code.
So if everithing is ok, where is the problem of my cofiguration?
What needs to be changed in libraries?
I've already scanned the library and I can't find references to 16MHZ or speed that have to be swapped.
Does anyone have any idea what might be wrong here? Anyone recommend another type of test to check the equipment?
Or the problem could be the lack of resistance in the two modules? I only have two modules to communicate and none has resistance. Should I add the jumper on the MCP2515 and put another equal resistance on the dashboard terminals?
Thanks in advance
Check to see if pin 4 on the TJA1050 chip has a signal that follows the CAN bus signal. If not then the transceiver Rx may be broken.
Check to see if pin 2 on the MCP2515 has the same signal as pin 4 on the TJA1050. If not then there may be a soldering problem.
(The chips are aligned in opposite directions, hence the pin numbering looks strange.)
With these small components you may find it easier to grasp a sewing pin or needle with the oscilloscope probe and then use the sharp tip to make electrical contact with the chip.
Yes, good catch. I thought your dashboard is inside a life system. CAN needs 120 Ohm termination resistors on each end. Close Jumper J1 and add another one at the other end. I doubt there is a resistor on the dashboard because CAN only needs two and usually has many more nodes.
Then please do the test described in reply #3. First just the module with jumper 1 closed and another at the end of your CAN bus. Send one message. It should be repeated continuously. Measure the CAN bitrate with your oscilloscope and confirm it is 50kbits/s.
Then connect the dashboard you should see the CAN message you send is no longer repeated because the dashboard acknowledges the message as valid. This is a CAN hardware function. All active nodes will acknowledge any valid CAN message.
thanks Klaus_k
so I put the jumper on MCP2515.
I repeated the test of loop just with MCP module (without connecting to dashboard).
50Kbps at 8MHZ so these are the results.
It comunicates??
There are two signals very close to CANL and CANH. They look like constant voltages but actually have a slight variation of 20mV. Are they normal?