-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Auto reinitialize can bus speed on the fly #4
Comments
Hello,
Unfortunatly, I was unable to reproduce the bug. What is your code ? The code I used is the following:
//------------------------------- Board Check ----------------------------------
#ifndef ARDUINO_ARCH_ESP32
#error "Select an ESP32 board"
#endif
//------------------------------- Include files --------------------------------
#include <ACAN_ESP32.h>
#include <core_version.h> // For ARDUINO_ESP32_RELEASE
//——————————————————————————————————————————————————————————————————————————————
// SETUP
//——————————————————————————————————————————————————————————————————————————————
void setup() {
//--- Switch on builtin led
pinMode (LED_BUILTIN, OUTPUT) ;
digitalWrite (LED_BUILTIN, HIGH) ;
//--- Start serial
Serial.begin (115200) ;
delay (100) ;
//--- Display ESP32 Chip Info
esp_chip_info_t chip_info ;
esp_chip_info (&chip_info) ;
Serial.print ("ESP32 Arduino Release: ") ;
Serial.println (ARDUINO_ESP32_RELEASE) ;
Serial.print ("ESP32 Chip Revision: ") ;
Serial.println (chip_info.revision) ;
Serial.print ("ESP32 SDK: ") ;
Serial.println (ESP.getSdkVersion ()) ;
Serial.print ("ESP32 Flash: ") ;
Serial.print (spi_flash_get_chip_size () / (1024 * 1024)) ;
Serial.print (" MB ") ;
Serial.println (((chip_info.features & CHIP_FEATURE_EMB_FLASH) != 0) ? "(embeded)" : "(external)") ;
Serial.print ("APB CLOCK: ") ;
Serial.print (APB_CLK_FREQ) ;
Serial.println (" Hz") ;
}
//——————————————————————————————————————————————————————————————————————————————
static uint32_t gBlinkLedDate = 0 ;
static const uint32_t bitRateArray [4] = { 125000, 250000, 500000, 1000000 } ;
static uint32_t gBitRateIndex = 0 ;
static const uint32_t MESSAGE_COUNT = 10 ;
//——————————————————————————————————————————————————————————————————————————————
// LOOP
//——————————————————————————————————————————————————————————————————————————————
void loop () {
if (gBlinkLedDate < millis ()) {
gBlinkLedDate += 1000 ;
digitalWrite (LED_BUILTIN, !digitalRead (LED_BUILTIN)) ;
//--- Configure ESP32 CAN
Serial.print ("Configure ESP32 CAN at ") ;
Serial.print (bitRateArray [gBitRateIndex]) ;
Serial.println (" bit/s") ;
ACAN_ESP32_Settings settings (bitRateArray [gBitRateIndex]) ;
gBitRateIndex = (gBitRateIndex + 1) % 4 ;
settings.mRequestedCANMode = ACAN_ESP32_Settings::LoopBackMode ;
// settings.mRxPin = GPIO_NUM_4 ; // Optional, default Tx pin is GPIO_NUM_4
// settings.mTxPin = GPIO_NUM_5 ; // Optional, default Rx pin is GPIO_NUM_5
const uint32_t errorCode = ACAN_ESP32::can.begin (settings) ;
if (errorCode == 0) {
Serial.print ("Bit Rate prescaler: ") ;
Serial.println (settings.mBitRatePrescaler) ;
Serial.print ("Time Segment 1: ") ;
Serial.println (settings.mTimeSegment1) ;
Serial.print ("Time Segment 2: ") ;
Serial.println (settings.mTimeSegment2) ;
Serial.print ("RJW: ") ;
Serial.println (settings.mRJW) ;
Serial.print ("Triple Sampling: ") ;
Serial.println (settings.mTripleSampling ? "yes" : "no") ;
Serial.print ("Actual bit rate: ") ;
Serial.print (settings.actualBitRate ()) ;
Serial.println (" bit/s") ;
Serial.print ("Exact bit rate ? ") ;
Serial.println (settings.exactBitRate () ? "yes" : "no") ;
Serial.print ("Distance ") ;
Serial.print (settings.ppmFromDesiredBitRate ()) ;
Serial.println (" ppm") ;
Serial.print ("Sample point: ") ;
Serial.print (settings.samplePointFromBitStart ()) ;
Serial.println ("%") ;
Serial.println ("Configuration OK!");
}else {
Serial.print ("Configuration error 0x") ;
Serial.println (errorCode, HEX) ;
}
//--- Loop for sending and receiving MESSAGE_COUNT messages
uint32_t sentCount = 0 ;
uint32_t receiveCount = 0 ;
while ((sentCount < MESSAGE_COUNT) || (receiveCount < MESSAGE_COUNT)) {
if (sentCount < MESSAGE_COUNT) {
CANMessage frame ;
const bool ok = ACAN_ESP32::can.tryToSend (frame) ;
if (ok) {
sentCount += 1 ;
Serial.print (" Sent ") ;
Serial.println (sentCount) ;
}
}
CANMessage frame ;
while (ACAN_ESP32::can.receive (frame)) {
receiveCount += 1 ;
Serial.print (" Received ") ;
Serial.println (receiveCount) ;
}
}
Serial.print (" STATUS 0x") ;
Serial.print (CAN_STATUS, HEX) ;
Serial.print (", RXERR ") ;
Serial.print (CAN_RX_ECR) ;
Serial.print (", TXERR ") ;
Serial.println (CAN_TX_ECR) ;
}
}
… Le 20 juil. 2022 à 01:37, hulktech ***@***.***> a écrit :
I have a stand alone automotive ecu with obd2 can bus protocol and i can change the baud rate speeds on the fly.In the other hand i use an esp32 with built in can bus controller to read the PID (RPM,VSS...)When i change the can bus speed on the ecu , i have an option to reinitialize the can bus speed on eps32 so it can reconnect.I just cycle in every 1sec the acan.begin with the aditional can bus speeds (128,250,500,1000) and pid request transmit. The problem is that it cannot reconnect to the bus althout i get the message "Configuration ESP32 OK!" . I think its stops transmiting the buffer. If i use acan 2515 with external controller (MCP 2515) the proble disapear and succeffully connected to the bus.The mc2515 was without interupts using 2515.poll();
Maybe the transmit buffer is over the limit? Please can you help me?
—
Reply to this email directly, view it on GitHub <#4>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AEWKZVFM2MDZIIQ3SHPPRBTVU432RANCNFSM54BU6MVQ>.
You are receiving this because you are subscribed to this thread.
|
Your sketch is not working when i change the can bus speed from ecu. To be more specific : When i change the ECU BUS speed @250kbs 00:29:10.764 -> STATUS 0x60, RXERR 56, TXERR 128 AND STOPS.. Also after a lot of search i get CAN BUS STATUS 0x4 in my sketch ,what is this error? Is it possible to restart the Can bus? Or recover? Thank you in andvace |
Strange, I have ran it without any problem during 30 minutes.
I have noticed you have this output:
00:29:10.764 -> STATUS 0x60, RXERR 56, TXERR 128
It means there are received errors (RXERR) and transmit errors (TXERR).
Questions :
- do you have removed the line "settings.mRequestedCANMode = ACAN_ESP32_Settings::LoopBackMode ;" ?
- is the ESP32 alone on the CAN bus ?
Pierre
… Le 20 juil. 2022 à 23:39, Gcopper ***@***.***> a écrit :
Your sketch is not working when i change the can bus speed from ecu.
To be more specific :
i start the ECU BUS speed 125kbs as EPS32 CAN bus initialize (gBitRateIndex = 0=125000)
it run succefully :
00:29:06.850 -> Configure ESP32 CAN at 125000 bit/s
00:29:06.850 -> Bit Rate prescaler: 16
00:29:06.850 -> Time Segment 1: 13
00:29:06.850 -> Time Segment 2: 6
00:29:06.850 -> RJW: 4
00:29:06.850 -> Triple Sampling: yes
00:29:06.850 -> Actual bit rate: 125000 bit/s
00:29:06.850 -> Exact bit rate ? yes
00:29:06.850 -> Distance 0 ppm
00:29:06.850 -> Sample point: 65%
00:29:06.850 -> Configuration OK!
00:29:06.850 -> Sent 1
00:29:06.850 -> Received 1
00:29:06.850 -> Received 2
00:29:06.850 -> Received 3
00:29:06.850 -> Received 4
00:29:06.850 -> Received 5
00:29:06.850 -> Received 6
00:29:06.897 -> Received 7
........
When i change the ECU BUS speed @250kbs
Its stops and i get :
00:29:10.764 -> STATUS 0x60, RXERR 56, TXERR 128
00:29:10.764 -> Configure ESP32 CAN at 250000 bit/s
00:29:10.764 -> Bit Rate prescaler: 8
00:29:10.764 -> Time Segment 1: 13
00:29:10.764 -> Time Segment 2: 6
00:29:10.764 -> RJW: 4
00:29:10.764 -> Triple Sampling: no
00:29:10.764 -> Actual bit rate: 250000 bit/s
00:29:10.764 -> Exact bit rate ? yes
00:29:10.764 -> Distance 0 ppm
00:29:10.764 -> Sample point: 70%
00:29:10.764 -> Configuration OK!
00:29:10.764 -> Sent 1
00:29:10.764 -> Sent 2
00:29:10.764 -> Sent 3
00:29:10.764 -> Sent 4
00:29:10.764 -> Sent 5
00:29:10.764 -> Sent 6
00:29:10.764 -> Sent 7
00:29:10.764 -> Sent 8
00:29:10.764 -> Sent 9
00:29:10.764 -> Sent 10
AND STOPS..
Also after a lot of search i get CAN BUS STATUS 0x4 in my sketch ,what is this error? Is it possible to restart the Can bus? Or recover?
Thank you in andvace
—
Reply to this email directly, view it on GitHub <#4 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AEWKZVGR6TK34ZFBHCZQU5LVVBWYJANCNFSM54BU6MVQ>.
You are receiving this because you commented.
|
yes the LoopBackMode is removed, In IDF there is option to Recovering CAN BUS from Bus-off State (https://docs.espressif.com/projects/esp-idf/en/release-v3.3/api-reference/peripherals/can.html) : esp_err_t can_initiate_recovery() Also there is option to Stop the CAN driver : Can you add this functions to your library? |
Just wanted to add that I have run into the same issue with the tx buffer not being sent. I haven't had time to create a min working example but the easiest trigger in my hardware setup (esp32 alone on canbus and esp32 with a single can logging device on canbus - loopback mode in both cases just sending out a random can packet onto the bus) has been to power cycle the 5V CAN for the can transceiver. The ACAN_ESP32 driver is never able to recover after 5V CAN is re-enabled despite re-calling the can.begin() routine. Only thing I noted was that attaching the CAN ISR in can.begin() fails when re-calling begin(). I briefly experimented with trying to de-initialize the can peripherals and free the can ISR without success despite getting rid of the failed isr attach call. Calling esp_restart() is not sufficient to recover from the issue either. Calling a deepsleep of 0 duration does allow recovering from the issue. If I get more time, I will investigate further. Edit: The CAN interrupt handler stops being triggered entirely in the fault state. The primary registers appear to recover after cycling 5V CAN, however interrupt does not trigger anymore:
All is pointing towards my earlier conclusion that the CAN ISR stops running, however, I'm not sure why. |
Hello,
I have reproduced the bug, and commenting out one line from the begin method enables again frame sending :
In ACAN_ESP32.cpp, comment out line #195 (CAN_TX_ECR = 0):
//--------------------------------- Set the Acceptance Filter
setAcceptanceFilter (inFilterSettings) ;
//--------------------------------- Set and clear the error counters to default value
CAN_EWLR = 96 ;
CAN_RX_ECR = 0 ;
// CAN_TX_ECR = 0 ;
//--------------------------------- Clear the Interrupt Registers
const uint8_t unusedVariable __attribute__((unused)) = CAN_INTERRUPT ;
You are right, the ISR should be freed before attaching a new one.
I have pushed a commit (f70bc99) on the https://github.com/pierremolinaro/acan-esp32 repository where I have a added a clean ISR free before performing a new alloc.
If it solves the bug, I will make a new release.
Best Regards,
Pierre
… Le 9 août 2022 à 05:39, matt6626 ***@***.***> a écrit :
Just wanted to add that I have run into the same issue with the tx buffer not being sent.
I haven't had time to create a min working example but the easiest trigger in my hardware setup (esp32 alone on canbus and esp32 with a single can logging device on canbus - loopback mode in both cases just sending out a random can packet onto the bus) has been to power cycle the 5V CAN for the can transceiver.
The ACAN_ESP32 driver is never able to recover after 5V CAN is re-enabled despite re-calling the can.begin() routine.
Only thing I noted was that attaching the CAN ISR in can.begin() fails when re-calling begin(). I briefly experimented with trying to de-initialize the can peripherals and free the can ISR without success despite getting rid of the failed isr attach call.
Calling esp_restart() is not sufficient to recover from the issue either. Calling a deepsleep of 0 duration does allow recovering from the issue.
If I get more time, I will investigate further.
—
Reply to this email directly, view it on GitHub <#4 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AEWKZVFTXAE4FHALNJMDGMTVYHHIHANCNFSM54BU6MVQ>.
You are receiving this because you commented.
|
I’ll give this a go in a day or two to confirm if this fixes the issue. Thanks for the fast turnaround. |
Unfortunately the CAN ISR still doesn't trigger on latest commit after the can 5V is re-enabled and begin() is called. Uncommenting following made no difference:
Only additional comment I can add is that no can packet is ever sent (ie. tx buffer never decreases) if any attempt to send a can packet is performed before 5VCAN is enabled (regardless of how many times begin() is called after this). Update: It is only when 5V can is turned off while still trying to send can packets that the issue occurs. Update 2: I dug through the idf twai driver to see if they do much different, only difference I found so far was calling periph_module_reset before periph_module_enable but that didn't help. Update 3: |
@matt6626 can you please post an example with ported twai can driver that can recover and send packets as you said? |
I've stripped out everything except hopefully the relevant min working can example (haven't checked whether it compiles). The main difference in the way I incorporated the idf-can was using no_ack mode instead of the loopback but I imagine principles are similar. |
I seem to be having this same issue. My setup has rare failures where receiving CAN just stops working on my board so I'm forced to reset the CAN peripheral, but if I try begin() and end()ing it fails to ever send more CAN messages. (The rare failures are definitely not simply being in CAN Bus Off mode as I've verified that I'm handling that. My best guess is I'm hitting some errata condition but I haven't looked into it very far) As a workaround I'm currently resetting the device by putting it into deep sleep and reinitializing everything, which works but is pretty tricky to get glitch free. |
The ACAN library works successfully with a CANbed board v1 (AT328U4 + MCP2515) and it can recover from BUS-OFF state. This one (acan-esp32), i confirm it can't recover from BUS-OFF state, and the receive ISR is not recover. Hope it can be fixed. |
I was able to get my board to recover from BUS-OFF by occasionally running the code below: bool CAN_check()
{
if (MODULE_CAN->SR.B.BS == 1 && MODULE_CAN->MOD.B.RM == 1)
{
MODULE_CAN->MOD.B.RM = 0;// leave reset
return true;
}
return false;
} Note it uses the register definitions in the file here: https://github.com/ThomasBarth/ESP32-CAN-Driver/blob/master/components/can/include/can_regdef.h I'm sure it can be ported easily over to not require that but I haven't bothered and just copied the file into my lib. |
I have published the 1.1.0 release that includes the recoveryFromBusOff method.
Pierre
… Le 21 sept. 2022 à 23:53, Andrea Inverardi ***@***.***> a écrit :
The ACAN library works successfully with a CANbed board v1 (AT328U4 + MCP2515) and it can recover from BUS-OFF state. This one (acan-esp32), i confirm it can't recover from BUS-OFF state, and the receive ISR is not recover. Hope it can be fixed.
—
Reply to this email directly, view it on GitHub <#4 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AEWKZVDKJD6MKOCG65PAOKDV7N7UDANCNFSM54BU6MVQ>.
You are receiving this because you commented.
|
Thank you for your contribution, I have published the 1.1.0 release that includes the recoveryFromBusOff method, based on the code you sent.
Pierre
… Le 23 sept. 2022 à 17:04, matthew-mower ***@***.***> a écrit :
The ACAN library works successfully with a CANbed board v1 (AT328U4 + MCP2515) and it can recover from BUS-OFF state. This one (acan-esp32), i confirm it can't recover from BUS-OFF state, and the receive ISR is not recover. Hope it can be fixed.
I was able to get my board to recover from BUS-OFF by occasionally running the code below:
bool CAN_check() { if (MODULE_CAN->SR.B.BS == 1 && MODULE_CAN->MOD.B.RM == 1) { MODULE_CAN->MOD.B.RM = 0;// leave reset return true; } return false; }
Note it uses the register definitions in the file here: https://github.com/ThomasBarth/ESP32-CAN-Driver/blob/master/components/can/include/can_regdef.h <https://github.com/ThomasBarth/ESP32-CAN-Driver/blob/master/components/can/include/can_regdef.h>
I'm sure it can be ported easily over to not require that but I haven't bothered and just copied the file into my lib.
—
Reply to this email directly, view it on GitHub <#4 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AEWKZVEXKH4GZXHBX5DFFF3V7XBHTANCNFSM54BU6MVQ>.
You are receiving this because you commented.
|
I'm trying compile examples using version 1.1.0 and unfortunately the didn't complete.I use 1.0.6 core and i dont know how i can include twai driver.Also when i update to core version 2.0.4 i have error "freertos/FreeRTOS.h: No such file or directory. Please is it possible to use your library with core 1.0.6 and how it will be done? Can someone help me.I want to use the recoveryFromBusOff method in 1.0.6 arduino core. Thank you advance |
Hello,
My library is designed for working with 2.0.5 esp32 platform version. It compiles without any error when I select the "MH ET LIVE ESP32MiniKit" board.
But I realize that selecting an other board, as the ESP32C3 Dev Module raises the error "soc/dport_reg.h: No such file or directory". The include path availabity depends from the selected board !
So, what is your board selection ?
My configuration is :
- MacIntel running macOS Monterey 12.6.1
- Arduino IDE 2.0.1
- ESP32 platform, version 2.0.5
- selected board "MH ET LIVE ESP32MiniKit".
I realize also that my "ESP32RecoveringFromBusOff.ino" sample code is just of copy of "ESP32ChangingBitRateOnTheFly.ino".
I will write an actual "ESP32RecoveringFromBusOff.ino" sample code, updating the include path, and make a new release.
Best regards,
Pierre
… Le 26 oct. 2022 à 01:30, Gcopper ***@***.***> a écrit :
I'm trying compile examples using version 1.1.0 and unfortunately the didn't complete.I use 1.0.6 core and i dont know how i can include twai driver.Also when i update to core version 2.0.4 i have error "freertos/FreeRTOS.h: No such file or directory.
Please is it possible to use your library with core 1.0.6 and how it will be done? Can someone help me.I want to use the recoveryFromBusOff method in 1.0.6 arduino core.
Thank you advance
—
Reply to this email directly, view it on GitHub <#4 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AEWKZVCIUEKIQZPF4ZZUXL3WFBUR3ANCNFSM54BU6MVQ>.
You are receiving this because you commented.
|
Ok, i successfully run busrecover, so i have another problem : Its stop receiving messages when i have a heavy load in the can bus network and trying to saving to EEPROM. |
I would also like to see an interrupt driven / callback handler for receiving CAN messages. |
I have a standalone automotive ecu with obd2 can bus protocol and i can change the baud rate speeds on the fly.In the other hand i use an esp32 with built in can bus controller to read the PID (RPM,VSS...)When i change the can bus speed on the ecu , i have an option to reinitialize the can bus speed on eps32 so it can reconnect. I just cycle in every 1sec the acan.begin with the additional can bus speeds (128,250,500,1000) and pid request transmit. The problem is that it cannot reconnect to the bus although i get message "Configuration ESP32 OK!" . I think its stops transmitting the buffer. If i use acan 2515 with external controller (MCP 2515) the problem disappear and succeffully connected to the bus.The mc2515 was without interrupts using 2515.poll();
Maybe the transmit buffer is over the limit? Please can you help me?
The text was updated successfully, but these errors were encountered: