Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix speed halved in ESP32-WROOM-32E module #33

Open
wants to merge 20 commits into
base: master
Choose a base branch
from

Conversation

sdp8483
Copy link

@sdp8483 sdp8483 commented Feb 20, 2022

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.

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 versions since this bit should not have been written to.
pilotak added a commit to pilotak/ESP32-Arduino-CAN that referenced this pull request Apr 9, 2022
danielkucera "It looks like the module is much more stable when reset bit is first set and then cleared."
@themagicm
Copy link

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

@sdp8483
Copy link
Author

sdp8483 commented Nov 7, 2023

@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#

@themagicm
Copy link

themagicm commented Dec 10, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants