CAN.h on ESP32 with arduino framework not working

Hi,

I am working on a can project using the EPS32 device and a can transceiver, I’ve found many libraries online but they seem to not work for me for some reason. One of the, in particular which seemed to be the most complete one: GitHub - sandeepmistry/arduino-CAN: An Arduino library for sending and receiving data using CAN bus..

Whenever I try to compile it, I have these parameters undefined, any ideas of what I can do about it?

lib/CAN/CAN.c:171:53: error: ‘DPORT_CAN_CLK_EN’ undeclared (first use in this function); did you mean ‘DPORT_REG_CLR_BIT’?
DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_CAN_CLK_EN);
^~~~~~~~~~~~~~~~
C:/Users/radu.rotaru/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32s3/include/soc/esp32s3/include/soc/dport_access.h:75:88: note: in definition of macro ‘_DPORT_WRITE_PERI_REG’
#define _DPORT_WRITE_PERI_REG(addr, val) (*((volatile uint32_t )(addr))) = (uint32_t)(val)
^~~
C:/Users/radu.rotaru/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32s3/include/soc/esp32s3/include/soc/dport_access.h:88:46: note: in expansion of macro ‘DPORT_WRITE_PERI_REG’
#define DPORT_SET_PERI_REG_MASK(reg, mask) DPORT_WRITE_PERI_REG((reg), (DPORT_READ_PERI_REG(reg)|(mask)))
^~~~~~~~~~~~~~~~~~~~
lib/CAN/CAN.c:171:5: note: in expansion of macro ‘DPORT_SET_PERI_REG_MASK’
DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_CAN_CLK_EN);
^~~~~~~~~~~~~~~~~~~~~~~
lib/CAN/CAN.c:172:31: error: ‘DPORT_PERIP_RST_EN_REG’ undeclared (first use in this function); did you mean ‘SYSTEM_PERIP_RST_EN0_REG’?
DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_CAN_RST);
^~~~~~~~~~~~~~~~~~~~~~
C:/Users/radu.rotaru/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32s3/include/soc/esp32s3/include/soc/dport_access.h:75:67: note: in definition of macro ‘_DPORT_WRITE_PERI_REG’
#define _DPORT_WRITE_PERI_REG(addr, val) (
((volatile uint32_t )(addr))) = (uint32_t)(val)
^~~~
C:/Users/radu.rotaru/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32s3/include/soc/esp32s3/include/soc/dport_access.h:85:46: note: in expansion of macro ‘DPORT_WRITE_PERI_REG’
#define DPORT_CLEAR_PERI_REG_MASK(reg, mask) DPORT_WRITE_PERI_REG((reg), (DPORT_READ_PERI_REG(reg)&(~(mask))))
^~~~~~~~~~~~~~~~~~~~
lib/CAN/CAN.c:172:5: note: in expansion of macro ‘DPORT_CLEAR_PERI_REG_MASK’
DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_CAN_RST);
^~~~~~~~~~~~~~~~~~~~~~~~~
lib/CAN/CAN.c:172:55: error: ‘DPORT_CAN_RST’ undeclared (first use in this function); did you mean ‘DPORT_DATE_REG’?
DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_CAN_RST);
^~~~~~~~~~~~~
C:/Users/radu.rotaru/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32s3/include/soc/esp32s3/include/soc/dport_access.h:75:88: note: in definition of macro ‘_DPORT_WRITE_PERI_REG’
#define _DPORT_WRITE_PERI_REG(addr, val) (
((volatile uint32_t *)(addr))) = (uint32_t)(val)
^~~
C:/Users/radu.rotaru/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32s3/include/soc/esp32s3/include/soc/dport_access.h:85:46: note: in expansion of macro ‘DPORT_WRITE_PERI_REG’
#define DPORT_CLEAR_PERI_REG_MASK(reg, mask) DPORT_WRITE_PERI_REG((reg), (DPORT_READ_PERI_REG(reg)&(~(mask))))
^~~~~~~~~~~~~~~~~~~~
lib/CAN/CAN.c:172:5: note: in expansion of macro ‘DPORT_CLEAR_PERI_REG_MASK’
DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_CAN_RST);
^~~~~~~~~~~~~~~~~~~~~~~~~
lib/CAN/CAN.c:176:39: error: ‘CAN_TX_IDX’ undeclared (first use in this function); did you mean ‘TWAI_TX_IDX’?
gpio_matrix_out(CAN_cfg.tx_pin_id,CAN_TX_IDX,0,0);
^~~~~~~~~~
TWAI_TX_IDX
lib/CAN/CAN.c:181:35: error: ‘CAN_RX_IDX’ undeclared (first use in this function); did you mean ‘TWAI_RX_IDX’?
gpio_matrix_in(CAN_cfg.rx_pin_id,CAN_RX_IDX,0);
^~~~~~~~~~
TWAI_RX_IDX
lib/CAN/CAN.c:242:20: error: ‘ETS_CAN_INTR_SOURCE’ undeclared (first use in this function)

Hi Radu!

See this website.

You have to rewrite “Platform.ini” file by following to this site.
This process should be done in any case you want to use an external library.

Good luck.
Hiro

Could it not just be that the library is for ESP32 chips and not ESP32S3 chips?

Thank you for the responses. I am using the ESP32-S3 version which is not compatible with the CAN libraries developed in the Arduino framework by default. They need to be adjusted to the new S3 configuration. However, Espressif developed their own can called TWAI for the later ESP32 chips and that works ok for me. For any one who’s struggling with the CAN on their new ESP check it out