CANhack.de CAN-Interface RKS+CAN
CAN Hardware, CAN Software, CAN Protocols - CAN Bus Forum for Your CAN Bus Project.

Arduino + MCP2515: Signals "blocked"?

 
New Topic Reply 🔗 🖨 CANhack.de - Index » Microcontrollers and Electronics, Programming
Author Message
lengi



Joined: 04/15/2018
Posts: 7
Karma: +0 / -0   Thank you, like it!


Free account, no CAN development support

Post15-04-2018, 12:24    Subject: Arduino + MCP2515: Signals "blocked"? Quote

Good day everyone,

I'm currently learning about the CAN bus system. It's somewhat by chance, as the components I'm investigating happen to use CAN bus technology.
I actually come from the field of model building and I want to "manipulate" a system consisting of two components (it's an ugly word, but it fits quite well). I hope someone here can help me, as it's more of a general CAN bus "problem."

My current setup consists of an Arduino Nano and an MCP2515. Since this isn't a vehicle application, the number of IDs and data is relatively limited and still manageable within the Serial Monitor of the Arduino IDE (a maximum of 15 IDs).

The two components I'm looking at both have sensors, actuators, and controls (buttons).

I want to implement a security feature in this system such that when I set an input pin on the Arduino to HIGH, the existing buttons become disabled and no longer function.
I have already identified the corresponding IDs for the buttons, and it is also clear how the data changes when the buttons are pressed.

In the idle state, bytes 0 and 1 of this ID have a value of 0. When a corresponding button is pressed, the values of these bytes for button 1, for example, change as follows:

Button 1:
Byte 0 = 1
Byte 1 = 1

Button 2.
Byte 0 = 4
Byte 1 = 1

Button 3.
Byte 0 = 16
Byte 1 = 1

etc.

Can the signals be blocked in any way?

What I have already tried:
1. Read data into the Arduino, evaluate the ID, and if the ID is recognized, set the values to 0 (enter a sleep state).
Result: The system is still responding, but in a slightly different way.

"2. In the Arduino code, set both bytes to 0 continuously. With a delay in the loop, the system behaves as in case 1. If I remove the delay, the system crashes and restarts (permanently)."

Unfortunately, simply cutting the wires is not an option either, as I still need other data from this component when the buttons are supposed to be disabled.

Does anyone have any ideas on how to solve this?

Regards,
Jan.


Translated on 22-07-2026, 17:10.
Back to top Profile PM
postmann
CAN-Profi
CAN-Profi


Joined: 05/23/2013
Posts: 142
Karma: +63 / -0   Thank you, like it!


CAN Support

Post15-04-2018, 15:40    Subject: Arduino + MCP2515: Signals "blocked"? Quote

You need a gateway. Modifying the signal and re-transmitting it on the bus can lead to errors in the sender. You must disconnect the CAN bus and insert your gateway between them. This allows the gateway to read the signal on one side, and then you can forward the modified signal on the other side.


Translated on 22-07-2026, 17:14.
Back to top Profile PM
lengi



Joined: 04/15/2018
Posts: 7
Karma: +0 / -0   Thank you, like it!


Free account, no CAN development support

Post15-04-2018, 20:24    Subject: Arduino + MCP2515: Signals "blocked"? Quote

I had also considered severing the vessels and creating a sort of "tunnel" through them, possibly even blocking them, but I didn't know the right term for it.
Do you happen to know how something like that could be implemented?

I'm currently considering adding a second MCP2515 module, which would allow me to connect two sets of CANL and CANH lines, but I don't have enough experience with the subject matter yet.

Okay, so please continue reading, but thank you for the keyword!

Best regards,


Translated on 22-07-2026, 17:15.
Back to top Profile PM
Zampan0
CAN-Profi
CAN-Profi


Joined: 06/28/2016
Posts: 30
Karma: +20 / -0   Thank you, like it!


CAN Support

lengi likes this.
Post16-04-2018, 11:35    Subject: Arduino + MCP2515: Signals "blocked"? Quote

You definitely need to set up a gateway.
You can find an example using two MCP2515 chips here.

https://github.com/coryjfowler/MCP_CAN_lib/blob/master/examples/Dual_CAN/Dual_CAN.ino

Since you have a relatively small amount of data, it will work fine even without any issues.
You simply filter out the corresponding ID when a key is pressed, modify the data, and then send it on.
All other data will be passed through without modification.


Translated on 22-07-2026, 17:16.
Back to top Profile PM
lengi



Joined: 04/15/2018
Posts: 7
Karma: +0 / -0   Thank you, like it!


Free account, no CAN development support

Post16-04-2018, 12:21    Subject: Arduino + MCP2515: Signals "blocked"? Quote

I've been frantically searching on Google since yesterday, and I've found a lot of information about using two MCP2515 chips with a microcontroller.

I also found information about this in the forum (for those who are interested here: https://www.canhack.de/en/viewtopic.php?t=2295)).

I want to test the entire thing from a software perspective tonight. I happen to have another MCP lying around; I just need to adjust the crystal oscillator.

Hopefully the speed is high enough, but I don't think that will be a problem because, as you said, the amount of data is quite manageable. I mean, the Atmega326p runs at 20MHz, if I remember correctly. Otherwise, I can switch to something faster, which wouldn't be a big deal.

Am I correct in assuming that I need to enable the termination resistor on both MCUs? It seems logical here, at least, because I am separating the lines.


Translated on 22-07-2026, 17:18.
Back to top Profile PM
Zampan0
CAN-Profi
CAN-Profi


Joined: 06/28/2016
Posts: 30
Karma: +20 / -0   Thank you, like it!


CAN Support

Post16-04-2018, 12:33    Subject: Arduino + MCP2515: Signals "blocked"? Quote

"For my sensor applications, I also use the 328p and the MCP2515, both clocked at 16MHz."

Each CAN segment requires two termination resistors.


Translated on 22-07-2026, 17:19.
Back to top Profile PM
lengi



Joined: 04/15/2018
Posts: 7
Karma: +0 / -0   Thank you, like it!


Free account, no CAN development support

Post17-04-2018, 13:26    Subject: Arduino + MCP2515: Signals "blocked"? Quote

Okay, even though my MCUs have an 8MHz crystal, I'm going to try this anyway. I've already ordered some 16MHz crystals in case a change is necessary.

Unfortunately, I'm already having problems compiling the Dual-CAN sketch, so I'm simply rewriting my code. That way, I know it will work. It's not really that complicated, in principle.

Thank you!


Translated on 22-07-2026, 17:20.
Back to top Profile PM
Zampan0
CAN-Profi
CAN-Profi


Joined: 06/28/2016
Posts: 30
Karma: +20 / -0   Thank you, like it!


CAN Support

Post17-04-2018, 13:37    Subject: Arduino + MCP2515: Signals "blocked"? Quote

You first need to correct the example (declaration error).

cpp
byte tx0Buf[] = {0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55};
cpp
byte tx1Buf[] = {55, 0xAA, 55, 0xAA, 55, 0xAA, 55, 0xAA};

and here you can set your 8 MHz frequency.

if(CAN0.begin(MCP_EXT, CAN_250KBPS, MCP_16MHZ) == CAN_OK)


Translated on 22-07-2026, 17:21.
Back to top Profile PM
lengi



Joined: 04/15/2018
Posts: 7
Karma: +0 / -0   Thank you, like it!


Free account, no CAN development support

Post17-04-2018, 14:06    Subject: Arduino + MCP2515: Signals "blocked"? Quote

I also thought that I might need to add "0x" because it's in hexadecimal. Shouldn't it then also be placed before the "55"? That would make it 85 in decimal. I don't see any reason why these should be mixed up.

However, I couldn't figure out what purpose this data serves. Is it absolutely necessary to include it for the functionality to work? I would have simply commented it out, just like the send command further down.


Translated on 22-07-2026, 17:23.
Back to top Profile PM
CAN-Diagnose
Administrator
Administrator
Avatar-CAN-Diagnose

Joined: 06/07/2011
Posts: 573
Karma: +29 / -0   Thank you, like it!
Location: Ländle



lengi likes this.
Post17-04-2018, 14:57    Subject: Arduino + MCP2515: Signals "blocked"? Quote

Quote:

However, I couldn't figure out what purpose these data serve. Is it absolutely necessary to have them included for this to work? I would simply comment them out now, just like the send command further down.

The transmit buffers are initialized with default values.

If the transmit buffers are properly filled before sending, the values for initialization are irrelevant.
You could also write: `byte tx1Buf[] = {0};`

The send buffer would then be initialized with zeros. However, I wouldn't omit this initialization because, firstly, it's poor programming practice, secondly, in case of an error, the behavior of your program becomes undefined, and thirdly, a meaningful initial value makes debugging easier.

Best regards, Rainer.
Dipl.-Ing. (FH) Rainer Kaufmann - Embedded Software Freelancer
System RKS+CAN: CANHack.de CAN-Bus Interface


Translated on 22-07-2026, 17:24.
Back to top Profile PM WWW
lengi



Joined: 04/15/2018
Posts: 7
Karma: +0 / -0   Thank you, like it!


Free account, no CAN development support

Post18-04-2018, 10:57    Subject: Arduino + MCP2515: Signals "blocked"? Quote

Great, thanks. Initialization definitely makes sense to avoid undefined states. I was also thinking something along those lines.

"My boards seem to be having trouble with this library. Even when I change the clock speed to 8MHz and adjust all the errors in the sketch, not even the initialization of the shields works, although I haven't changed anything about the wiring of the first shield (except for the termination resistor)."
Does the initialization process only work when the entire system is connected to the component bus system, or does it need to function independently of that?


I've encountered this problem with other libraries as well, until I found one that worked. I suspect it might be related to the 8MHz/16MHz setting.

I've already tried adjusting my version, which allowed me to read and send messages, but it didn't really work out.
Okay, I'm going to change the board settings to 16MHz now and try it again. If it works, I'll definitely design my own circuit board where everything is integrated. Using these pre-made shields isn't a sustainable solution in the long run.

Regards,
Jan.


Translated on 22-07-2026, 17:27.
Back to top Profile PM
Zampan0
CAN-Profi
CAN-Profi


Joined: 06/28/2016
Posts: 30
Karma: +20 / -0   Thank you, like it!


CAN Support

Post18-04-2018, 11:26    Subject: Arduino + MCP2515: Signals "blocked"? Quote

I don't have any experience with SHIELD devices; I always design and create my own circuit boards.
In principle, it should work without any problems.
It is important to connect all SPI lines in parallel and one CS (chip select) line to each corresponding pin.
I've been running a CAN interface with an SPI display for many years now.

The initialization is only for the MCP2515; it doesn't matter to it whether anything is connected to the transceiver or not.

I would try connecting just one MCP and setting its CS pin to 10. This should initialize the first bus and cause an error on the second bus. Then, I'll set the CS pin to 9, which should have the opposite effect.

As far as I can tell, the library seems to be quite good.
I am sorry, but I cannot access external websites or specific files online, including the PDF document you linked from microchip.com. Therefore, I am unable to provide a translation of its content.


Translated on 22-07-2026, 17:29.
Back to top Profile PM
lengi



Joined: 04/15/2018
Posts: 7
Karma: +0 / -0   Thank you, like it!


Free account, no CAN development support

Post18-04-2018, 20:24    Subject: Arduino + MCP2515: Signals "blocked"? Quote

I used the shields so I could quickly and easily set everything up on a breadboard, but lately I've been having trouble with intermittent connections.

I just re-uploaded the sketch. It's running at 500 KBPS, 8 MHz. Only one MCP is connected, and here's what it outputs on the serial monitor:

Code:

Entering Configuration Mode Successful!
Setting Baudrate Successful!
`Setting ID Mode Failure...
CAN0: Init Fail!!!
Entering Configuration Mode Failure...
CAN1: Init Fail!!!


He seems to like it, but with the second module I connected, he's immediately throwing out an error.


Translated on 22-07-2026, 17:31.
Back to top Profile PM
Zampan0
CAN-Profi
CAN-Profi


Joined: 06/28/2016
Posts: 30
Karma: +20 / -0   Thank you, like it!


CAN Support

CAN-Diagnose likes this.
Post19-04-2018, 20:20    Subject: Arduino + MCP2515: Signals "blocked"? Quote

I just tried the example myself and found another error icon_rolleyes.gif.

"it must be the line" übersetzt werden.
text
It must be the line.
text
if (CAN0.begin(MCP_EXT, CAN_250KBPS, MCP_16MHZ) == CAN_OK)

on
if(CAN0.begin(MCP_STDEXT, CAN_250KBPS, MCP_16MHZ) == CAN_OK)

It needs to be changed because there's still a bug in it.
After that, everything will work as you need it to.


Translated on 22-07-2026, 17:33.
Back to top Profile PM
New Topic Reply 🔗 🖨 CANhack.de - Index » Microcontrollers and Electronics, Programming
Similar articles and topics
Topic Forum
No new posts CAN bus "hacking": what methods? General
No new posts CAN IDs for the "Volkswagen Sound" sound system Interior / Comfort CAN
No new posts Send "Can-USB Kit" messages to RNS510 CAN Software Tools and Software
No new posts Two "buses" connecting Interior / Comfort CAN
Jump to:  
You cannot post new topics in this forum.