Contact Us  Call us Now - 0034 938 760 191

Forum Controllers/PLC

Welcome!

This community is for professionals and enthusiasts of our products and services. Share and discuss the best content and new marketing ideas, build your professional profile and become a better marketer together.

0

CAN not initializing on PLC ESP32 21

Avatar
Eduard

Currently implementing CAN communication on a PLC ESP32 21. CAN0.begin() always returns false.


- I'm using the examples from here: https://www.industrialshields.com/es_ES/blog/blog-industrial-open-source-1/can-spi-with-esp32-plc-family-608


- I've set the DIP switches 2 & 4 to ON on the bottom face of the PLC.


- I'm pretty sure my client chose Expansor slot 1 when buying the PLC, but just in case I've tried both configurations:

For Expansor 1:  RSTpin 6,  INTpin 5,  pinCS 32

For Expansor 2:  RSTpin 3,  INTpin 1,  pinCS 2


- Is the quartz clock on the CAN board 8MHZ? Could one with 16MHz have been installed by mistake (I say this because it happened to me once with a similar CAN board)?


- From what I've read about Arduino CAN boards in general, the initialization doesn't require that any other device is connected through H & L lines, nor that I connect the 120ohm terminations yet. I've still tried it just in case.


- Where exactly are the 3 pins physically connected? Are RSTpin and INTpin on the expansor, and pinCS on the ESP32?


Thanks for any help.

Avatar
Discard
1 Answer
0
Best Answer

Hello Eduard, 

Let me answer your questions:

- I've set the DIP switches 2 & 4 to ON on the bottom face of the PLC.

That is okay for expansion slot 2. For expansion slot you do not need to configure anything.

- I'm pretty sure my client chose Expansor slot 1 when buying the PLC, but just in case I've tried both configurations:

For Expansor 1:  RSTpin 6,  INTpin 5,  pinCS 32

For Expansor 2:  RSTpin 3,  INTpin 1,  pinCS 2

Expansor 1 is usually used when there is only one expansion board (regardless of what is chosen on the website). Nonetheless, you can try both. Also, if you remove the top cover (where the LEDs are) you can see where the expansion boards is located:

  • 1 is the one further away form the Ethernet port.
  • 2 is the one next to the Ethernet port.

- Is the quartz clock on the CAN board 8MHZ? Could one with 16MHz have been installed by mistake (I say this because it happened to me once with a similar CAN board)?

The CAN post you link was in fact updated not long ago due to the oscillator frequency.

The oscillator on our CAN devices works at 10MHz. For this reason, the library and examples on the post have the "MCP_10MHZ" macro, to properly configure the CAN controller. 

- From what I've read about Arduino CAN boards in general, the initialization doesn't require that any other device is connected through H & L lines, nor that I connect the 120ohm terminations yet. I've still tried it just in case.

That is right,  the initialization can be done without any other device connected to the CAN bus. 

Regarding the impedance adaptation, the CAN board already has a 120Ohm resistor in it, active by default. If you need to disable it, it can be done by removing a jumper located on the board.

- Where exactly are the 3 pins physically connected? Are RSTpin and INTpin on the expansor, and pinCS on the ESP32?

That is right. The used pins are:

  • Expansion slot 1:
    • The ESP32 SPI pins (MISO, MOSI, SCK)
    • CS: GPIO 2 (ESP32)
    • RST: 3 (expansor)
    • INT: 1 (expansor)
  • Expansion slot 2:
    • The ESP32 SPI pins (MISO, MOSI, SCK)
    • CS: GPIO 32 (ESP32)
    • RST: 6 (expansor)
    • INT: 5 (expansor)


Please try one of the examples on the post, for example the receive one. After uploading it, you should see the following message on the serial monitor (with no need to have any other device connected through CAN):


Entering Configuration Mode Successful!
Setting Baudrate Successful!
MCP2515 initialized successfully!


Please try this and let us know what results you get!




1 Comment
Avatar
Discard
Avatar
Eduard
-

I confirm that both examples work perfectly on my PLC. Thank you for all the work!

For anyone doing the same, you can include custom libraries in your project by putting them in a folder named 'src' next to your sketch, and including them in the code like this (remember to use " " rather than <> :

#include "src/Adafruit_MCP23008/Adafruit_MCP23008.h"
#include "src/MCP_CAN/mcp_can.h"