3

compared to the microchip's PICs:

pic16f's does not have an onboard CAN peripheral. so you need an SPI - CAN controller (like MCP2515).

some PIC18f's have an onboard CAN controller, and only need a CAN transceiver. In these cases there are exclusive TX and RX pins to be used.

Are there specific pins to be used as a CAN bus on esp32? peripherals like adc, i2c and others need to use specific pins. Does this happen with CAN too?

I'm using the following configuration: 2 ESP32 devboard boards - arduino on PlatformIO Pin 5 as TX and pin 4 as RX (already in the CAN library), 2 Sn65hvd230 transceiver modules

I looked for information about it in the documentation, but I couldn't find it.

I appreciate any help.

2
  • 1
    You can use any pins (within reason). What pins have you told it to use in your code?
    – Majenko
    Feb 3, 2021 at 20:14
  • You can edit your question to fill out the details that are being asked for here.
    – timemage
    Feb 3, 2021 at 21:57

2 Answers 2

5

I looked for information about it in the documentation, but I couldn't find it.

Well, some of their documentation says:

The TWAI controller’s interface consists of 4 signal lines known as TX, RX, BUS-OFF, and CLKOUT. These four signal lines can be routed through the GPIO Matrix to the ESP32’s GPIO pads.

And that sort of seems to be backed up by their examples that make use of TWAI_GENERAL_CONFIG_DEFAULT to generate a structure with the arguments filling fields that use gpoi_num_t.

There is documentation to the GPIO Matrix generally in the ESP32 technical reference. It is described there as follows:

The ESP32 chip features 34 physical GPIO pads. Each pad can be used as a general-purpose I/O, or be connected to an internal peripheral signal. The IO_MUX, RTC IO_MUX and the GPIO matrix are responsible for routing signals from the peripherals to GPIO pads. Together these systems provide highly configurable I/O.

(My emphasis in the above).

And also there is a table (Table 25) in Appendix 2 of the ESP32 datasheet for the GPIO matrix.

Many of the small chips, like the PIC16F series ones, have no internal routing for peripherals, except for deciding which of one or two special functions to use rather than GPIO and ADC channels. Most of the of the ATTiny and ATMega series AVR chips that are not in the 0- and 1- series don't. The 1- and 0- series an a few of the older series parts (e.g. ATTiny841) give you a fixed number (usually two) pre-determined destinations to chose from for some peripherals.

This sort of thing gets more flexible as you get into larger chips, but the having that "matrix" feature that lets choose more freely is comparatively rare. Some of the Cypress "PSoC" labeled chips have this sort of feature.

2

When using arduino and the esp32 core, any pin can be assigned to the builtin TWAI controller.

If you use the esp32_can library https://github.com/collin80/esp32_can you may change the pin assignment in the following file:

C:\Users\USER\Documents\Arduino\libraries\esp32_can-master\src\esp32_can.cpp

//Set these to the proper pin numbers for you board. Set by default to correct for EVTV ESP32-Due
//rxpin txpin
ESP32CAN attribute((weak)) CAN0(GPIO_NUM_16, GPIO_NUM_17) ;

//Select and uncomment the proper module you've got connected via SPI
//CS, INT
MCP2517FD attribute((weak)) CAN1(5, 27) ;
//MCP2515 attribute((weak)) CAN1(5, 27) ;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.