Student112

Hi ,
New in OpenPLC,I want to exchange data between two Arduinos Nano using CAN communication with MCP2515,
so I want to ask if I should only add the two arduinos as Slave on OpenPLC or I need to do something else  on OpenPLC for my CAN communication.Thanks
Reply 0 0
thiagoralves
OpenPLC does not support CAN bus
Reply 0 0
BenKissBox
Hi Student112,

I understand that you want to have 3 nodes on the CAN bus : an OpenPLC node and two Arduinos. Am I right ?

In that case, there are two things to solve before even thinking of integrating CAN into OpenPLC.

The first one is what CAN adapter you are going to use in the computer hosting OpenPLC. If you use a Linux machine, CAN can be reached through SocketCAN interface. As Thiago said, this is not supported nativerly in OpenPLC but you can reach it by writing a C module which acts as a gateway between SocketCAN and the OpenPLC kernel.
To know how to write and use C modules within OpenPLC, you can take a look here : https://openplc.discussion.community/post/embedding-ccode-in-a-function-block-10390636
and also at the documentation I wrote (you can find it here : https://openplc.discussion.community/post/tutorial-for-c-code-integration-in-openplc-and-beremiz-11666716

If you use a Windows machine to run OpenPLC and you want to use CAN, then say hello to proprietary hardware and drivers. There is no equivalent of SocketCAN in Windows world, and every CAN interface vendor uses its own driver and API, thinking it is better than the others... 😠
To acces these drivers, you can also use some C module.

The second big thing to consider is the protocol you want to use between all the CAN nodes. CAN itself is a very simple protocol which carries up to 8 bytes using identfiers on 11 or 29 bits. There are a lot of application protocols using CAN : CANOpen, DeviceNet, J1939, CBUS, CAN Kingdom, etc...

If you want to use a professional application layer (CANOpen being one of the best for automation), then you will need to implement a complete communication stack, which is a really, realy hard work, especially if you do it from scratch.

So, if you just want to exchange a few bytes between the 3 stations, then using the basic protocol is probably the best thing to do as it will be as simple as writing data bytes into a buffer and send a transmit command to the CAN controller. But in all cases, you will need to deal with C interface in OpenPLC and understand how the MCP2515 works (and how SocketCAN works, if you use it too)

Benoit
Reply 0 0
Student112
Thank you very much
Reply 0 0
Reply