Arduino-FOC: [BUG] ESP32-S3 Stuck in adc functions
Describe the bug When trying for example the Inline current sensing test, the ESP32-S3 (esp32-s3-devkitc-1 v1.0), the esp32 is not printing anything. After some debugging, we discovered that it is stuck in adcRead (https://github.com/simplefoc/Arduino-FOC/blob/master/src/current_sense/hardware_specific/esp32/esp32s_adc_driver.cpp). We found that the while loop checking if the adc is ready is causing the problem (with our pin configuration, its the bottom one in line 241): https://github.com/simplefoc/Arduino-FOC/blob/05954cb9691534dd478407505d810a68f1673a5e/src/current_sense/hardware_specific/esp32/esp32s_adc_driver.cpp#L237-L243
When adding this line of code, I can see “reg: 80160000” inside the serial monitor:
Serial.printf("reg %x\n", READ_PERI_REG(SENS_SAR_MEAS1_CTRL2_REG));
Describe the hardware setup For us it is very important to know what is the hardware setup you’re using in order to be able to help more directly
- Which motor: None (devboard only)
- Which driver: None
- Which microcontroller: Espressif ESP32-S3-DevKitC-1
- Which position sensor: None
- Current sensing used? Yes
IDE you are using
- Visual Studio Code with Platformio
- espressif32@6.3.2 (latest)
[env:esp32-s3-devkitc-1]
platform = espressif32
board = esp32-s3-devkitc-1
framework = arduino
lib_deps = askuric/Simple FOC@2.3.0
lib_archive = false
monitor_speed = 115200
upload_speed = 921600
We tried this with multiple esp32-s3 boards, and did not get it to work. When using this platformio configuration for normal esp32 (not S3!), it works however (same code):
[env:esp32dev]
platform = espressif32@2.0.0
board = esp32dev
framework = arduino
lib_deps = askuric/Simple FOC@2.2.0
lib_archive = false
monitor_speed = 115200
upload_speed = 921600
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 19 (5 by maintainers)
Commits related to this issue
- bugfix for #295 and #320 + added #346 — committed to simplefoc/Arduino-FOC by askuric 2 years ago
Can confirm low side current sense is working on my ESP32s3 as well (on v2.3.4)
Hey guys, The fix to this issue is in the new release v2.3.4. The esp32 driver has been rewritten and the fast ADC code stripped to the bare minimum components.
Let me know if some of you had the time to test the code and confirm that the issue is fixed.
On my esp32-s3 the issue does no longer exist.
I discovered that in addition to resolving bug #346, if I use analogRead to read the sensor pin before sensor initialization, and then proceed with the initialization, blocking issues do not occur. I have dumped the following registers:
0x60008838: 0xfffff 0x60008824: 0x60050001 0x60008830: 0x80260000 0x6000883c: 0x0 0x60008820: 0x7000f3 0x60008818: 0x10001 0x60008840: 0x0
However, I have not yet identified the problem. Has anyone else encountered this issue?
I think I have located this problem. This is a bug. Each ADC of esp32s3 has 10 channels 0~9, and the SENS_SAR_MEAS1_CTRL2_REG register shows the status of ADC1, and SENS_SAR_MEAS2_CTRL2_REG shows the status of ADC2. But when I use GPIO9, currently The judgment detects BIT16 of SENS_SAR_MEAS2_CTRL2_REG, which belongs to ADC2. When I change if(channel > 7) to if(channel > 9), my current program is normal. But I think this method may not be appropriate for ADC2