CAN issue with Arduino Nano ESP32

Hello everyone,

I have just bought an Arduino Nano ESP32 that I would like to use for CAN communication. This is why I downloaded the CAN library by Sandeep Mistry. Unfortunaltely, when I verify my code using this library with the Arduino Nano ESP32 board selected, it does not work (exit status 1). However, if I select and Arduino Uno board, it works. How come? What should I do?

Thanks a lot in advance for your help !

Use the one that works!

Unfortunately, I do not think this will really solve the problem and the Arduino Uno does not have an ESP32, so it will not be able to handle the CAN protocol once I will upload the code on it

I have quite a few CAN nodes running on the original Nano. Solid like a rock. A lot of success or failure depends on the skill of the programmer.

Please explain why you need an ESP32 to handle the CAN protocol. I use the MPC2515 boards from china and they work great with the Nano. The MPC2515

Features from the first page of the data sheet, what is missing?
• Implements CAN V2.0B at 1 Mb/s:

  • 0 to 8-byte length in the data field
  • Standard and extended data and remote frames
    • Receive Buffers, Masks and Filters:
  • Two receive buffers with prioritized message storage
  • Six 29-bit filters
  • Two 29-bit masks
    • Data Byte Filtering on the First Two Data Bytes
    (applies to standard data frames)
    • Three Transmit Buffers with Prioritization and
    Abort Features
    • High-Speed SPI Interface (10 MHz):
  • SPI Modes 0,0 and 1,1
    • One-Shot mode Ensures Message Transmission
    is Attempted Only One Time
    • Clock Out Pin with Programmable Prescaler:
  • Can be used as a clock source for other device(s)
    • Start-of-Frame (SOF) Signal is Available for Monitoring the SOF Signal:
  • Can be used for time slot-based protocols and/or bus diagnostics to detect early bus
    degradation
    • Interrupt Output Pin with Selectable Enables
    • Buffer Full Output Pins Configurable as:
  • Interrupt output for each receive buffer
  • General purpose output
    • Request-to-Send (RTS) Input Pins Individually
    Configurable as:
  • Control pins to request transmission for each transmit buffer
  • General purpose inputs
    • Low-Power CMOS Technology:
  • Operates from 2.7V-5.5V
  • 5 mA active current (typical)
  • 1 μA standby current (typical) (Sleep mode)
    • Temperature Ranges Supported:
  • Industrial (I): -40°C to +85°C
  • Extended (E): -40°C to +125°C
    • AEC-Q100 Qualified

Description
Microchip Technology’s MCP2515 is a stand-alone Controller Area Network (CAN) controller that implements the CAN specification, Version 2.0B. It is capable of transmitting and receiving both standard and extended data and remote frames. The MCP2515 has two acceptance masks and six acceptance filters that are used to filter out unwanted messages, thereby reducing the host MCU’s overhead. The MCP2515 interfaces with microcontrollers (MCUs) via an industry standard Serial Peripheral Interface (SPI).

After reading the data sheet I created 2 nodes, two Nanos and two controllers. connected two of them together via the CAN bus and loaded Cory Fowler's MCP-can, one for transmit the second for receive it worked first time.

Hi @manou002. Unfortunately the "CAN" library is not compatible with the ESP32-S3 microcontroller of the Nano ESP32 board:

I see that the "Arduino ESP32 Boards" platform of the Nano ESP32 does have a built-in CANBUS support. There are some examples demonstrating how to use it under the File > Examples > ESP32 > TWAI menu.

I also see information about using the "ESP32-TWAI-CAN" library with ESP32-S3 boards:

Hello @gilshultz , thanks a lot for your answer! I do not especially need an Arduino Nano ESP32, I didn't know the MPC2515 combined with an original Nano could do the job. So I could use a MPC2515, but for my application, I would like to communicate with a motor that uses CAN protocol. Do you think that the MPC2515 could be used to easily communicate with the motor through CAN ?

Thanks a lot!

Hi @ptillisch , thanks for your complete answer!

I did not even know there was an example file, thanks a lot for this!

Also, concerning the ESP32-TWAI-CAN library, it seems quite complex to use (from what I read in the link you shared), so I think I'll try to use the example file!

I hope this will allow me to interface the Arduino with the motor driver through CAN!

Thanks a lot!

1 Like

I cannot say, I know nothing about the particular motor you have. If I were to guess if they followed the standard protocol it will work fine. It works with several home automation projects, automotive OBDII, and many others. I have of it not working but eventually it would up being cockpit error. Be sure to follow the rules for the bus. 120 Ohm resistors only on the ends of the bus, on the module you connect a jumper. Be sure the bus is a few feet long if possible but not necessary. Do not add pull up or pull down resistors, just two 120 ohm resistors making the bus aboug 60 Ohms. For a few $ give it a try especially if you have other Arduinos. I have it working on a UNO and a WeMos D1 R1 I connected it and it worked, I forgot about the voltage as the R1 is 3.3V but it has been running for a little over two years so consider myself lucky I did not have to change the driver chip.