ESP32-Arduino-CAN
ESP32-Arduino-CAN copied to clipboard
fix speed halved in ESP32-WROOM-32E module
ESP32 ECO3 added a configurable bit that will cause CAN bus speeds to be halved in new V3 core 32E module.
This bit is in TWAI_INT_ENA_REG
, bit4 which was previously reserved.
Change respects reserved bit and should not cause issues for previous core versions since this bit was reserved and should not have been written to.
I'm still seeing issues.
I have an ESP32-WROOM-32D and am using this library for 1MBPS CAN BUS transfer.
This is what I have in CAN.c:
// select time quantum and set TSEG1
switch (CAN_cfg.speed) {
case CAN_SPEED_1000KBPS:
MODULE_CAN->BTR1.B.TSEG1 = 0x4;
__tq = 0.125;
break;
case CAN_SPEED_800KBPS:
MODULE_CAN->BTR1.B.TSEG1 = 0x6;
__tq = 0.125;
break;
case CAN_SPEED_200KBPS:
MODULE_CAN->BTR1.B.TSEG1 = 0xc;
MODULE_CAN->BTR1.B.TSEG2 = 0x5;
__tq = 0.25;
break;
default:
MODULE_CAN->BTR1.B.TSEG1 = 0xc;
__tq = ((float) 1000 / CAN_cfg.speed) / 16;
}
// set baud rate prescaler
MODULE_CAN->BTR0.B.BRP = (uint8_t) round((((APB_CLK_FREQ * __tq) / 2) - 1) / 1000000) - 1;
/* Set sampling
* 1 -> triple; the bus is sampled three times; recommended for low/medium speed buses (class A and B) where
* filtering spikes on the bus line is beneficial 0 -> single; the bus is sampled once; recommended for high speed
* buses (SAE class C)*/
MODULE_CAN->BTR1.B.SAM = 0x1;
// MODULE_CAN->IER.U &= ~(1 << 4); // Clear the BRP_DIV bit
// MODULE_CAN->IER.U = 0xef;
MODULE_CAN->IER.U = 0xff;
Stumped... not sure how to enable 1MBPS
@themagicm This library is outdated and is not maintained by the author. I have forked and updated it for my own purposes using the Espressif IDF API. I have linked it down below if you are interested in using it. https://github.com/sdp8483/ESP32-Arduino-CAN
Also check out the Espressif IDF page about the CAN peripheral and the API used. This works in the Arduino framework so you can use it directly in your code or use the library I linked above that also implements this API. https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/twai.html#
I'm using it at 1mbit but it feels slow? Does that make sense?
Sent from Proton Mail mobile
-------- Original Message -------- On Nov 7, 2023, 8:40 AM, Sam Perry wrote:
@.***(https://github.com/themagicm) This library is outdated and is not maintained by the author. I have forked and updated it for my own purposes using the Espressif IDF API. I have linked it down below if you are interested in using it. https://github.com/sdp8483/ESP32-Arduino-CAN
Also check out the Espressif IDF page about the CAN peripheral and the API used. This works in the Arduino framework so you can use it directly in your code or use the library I linked above that also implements this API. https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/twai.html#
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>