Differences in CAN clock in ESP-WROOM-32 module

keesza
Posts: 7
Joined: Mon Jun 17, 2024 5:47 pm

Differences in CAN clock in ESP-WROOM-32 module

Postby keesza » Mon Jun 17, 2024 6:09 pm

I have 2 Olimex CAN-EVB boxes; 1 of 2017 and 1 of last year. I made a CAN application with the first one and it is working for most standard bitrates, however not lower than 25 MB/sec. This was a known problem and is related to the 80 MHz APB clock.
The new one is flashed with exactly the same software and I noticed the communication on the CANbus was not correct. It was communicating on half the bitrate as the one specified. When I set the base frequency to 40 MHz in stead of 80, it was functioning well again.
Two questions:
1. Is my conclusion correct that the base frequency of the ESP-WROOM-32 for CAN is lowered to 40 MHz? If I ask for getApbFrequency() it still responds with 80 MHz.
2. If it is 40 MHz for CAN now, how can I this frequency for my application (something like getCanFrequency())? I like to make my application universal.

Kees

ESP_Sprite
Posts: 9773
Joined: Thu Nov 26, 2015 4:08 am

Re: Differences in CAN clock in ESP-WROOM-32 module

Postby ESP_Sprite » Tue Jun 18, 2024 2:54 am

From what I remember, newer ECOs of the ESP32 have a change where we provide additional divider bits so the clock speed can go lower. However, this should be transparent to the application. Are you perhaps still using a very old ESP-IDF version for this?

keesza
Posts: 7
Joined: Mon Jun 17, 2024 5:47 pm

Re: Differences in CAN clock in ESP-WROOM-32 module

Postby keesza » Tue Jun 18, 2024 7:32 am

My program is coded in Arduino IDE. I have to check which version of ESP-IDF has been used and check if this can be updated without any problems.
Does this mean that the clock used by CAN is still APB_CLK_FREQ and this value will be 40000 in stead of 80000 in the newer ESP-IDF?

ESP_Sprite
Posts: 9773
Joined: Thu Nov 26, 2015 4:08 am

Re: Differences in CAN clock in ESP-WROOM-32 module

Postby ESP_Sprite » Tue Jun 18, 2024 8:49 am

It should still use the APB bus at 80MHz. I'm not sure why you're getting a lower rate.

keesza
Posts: 7
Joined: Mon Jun 17, 2024 5:47 pm

Re: Differences in CAN clock in ESP-WROOM-32 module

Postby keesza » Tue Jun 18, 2024 11:35 am

I did an update of the board in Arduino IDE and now I should have a version of IDF in the range of 4. However now I get an error during compilation. Three lines are relevant in my CAN library:

#include "esp_intr.h"
.
.
gpio_matrix_out(CAN_cfg.tx_pin_id, CAN_TX_IDX, 0, 0);
.
.
gpio_matrix_in(CAN_cfg.rx_pin_id, CAN_RX_IDX, 0);

Compiling it in this way gives the error: esp_intr.h not found.

After deleting the #include line the CAN_TX_IDX and CAN_RX_IDX are not found.

Filling in any value of these variables compiles correctly, however probably not the right values because I don't have CAN communication. I guess I have to fill in an interrupt pointer. The application uses the FREERTOS queue handler.

Suggestions I saw on internet about replacing esp_intr.h by esp_intr_alloc.h does not work because CAN_TX_IDX and CAN_RX_IDX are not included here.

I'm stuck now.

keesza
Posts: 7
Joined: Mon Jun 17, 2024 5:47 pm

Re: Differences in CAN clock in ESP-WROOM-32 module

Postby keesza » Tue Jun 18, 2024 12:59 pm

Previous problem solved by:
#include "soc/gpio_sig_map.h" in stead of #include "esp_intr.h"

However still a factor of 2 difference in bitrate of an old and a new module.

Same problem is mentioned in:

https://esp32.com/viewtopic.php?f=12&t= ... us#p122107

My application is based on the same library, which I had to change to make it universal.

What was meant with "additional divider bits"? Can I check these bits anywhere?

keesza
Posts: 7
Joined: Mon Jun 17, 2024 5:47 pm

Re: Differences in CAN clock in ESP-WROOM-32 module

Postby keesza » Tue Jun 18, 2024 4:31 pm

Also

https://esp32.com/viewtopic.php?f=19&t= ... us#p130730

is about the same issue in fact.

Older CAN libraries always end up with a bitrate of 50% of the calculated one on new devices.

keesza
Posts: 7
Joined: Mon Jun 17, 2024 5:47 pm

Re: Differences in CAN clock in ESP-WROOM-32 module

Postby keesza » Wed Jun 19, 2024 8:35 am

Found the reason for the problem on page 38 of datasheet of ESP32 (https://www.espressif.com/sites/default ... eet_en.pdf).

bit rates:
– from 25 Kbit/s to 1 Mbit/s in chip revision v0.0/v1.0/v1.1
– from 12.5 Kbit/s to 1 Mbit/s in chip revision v3.0/v3.1

The older CAN libraries were developed based on the earlier versions. This means a basic clock of 80 Mhz, which gives as lowest bitrate 25 kbit/sec. The newer versions have a basic clock of 40 MHz which gives the opportunity to go down to 12.5 kbit/sec. For getting the right bitrate in CAN (TWAI) you need to know what is the basic clock. By setting 2 bytes in the CAN controller you get the right bitrate.

Users of old libraries should replace APB_CLK_FREQ by 40000 and after that they will get the right bitrates for the new versions.

To get an universal solution it would be nice if it is possible to read out the version of the ESP32 chip in software (or any other parameter which is different in the versions). In that way it is possible to change the formula of BRP (Bit Rate Prescaler) in the application.

I hope I clarified the situation also for other users.

Who is online

Users browsing this forum: Bing [Bot] and 64 guests