Issue with SPI Driver in ESP-IDF Porting

Sree23
Posts: 3
Joined: Fri Feb 02, 2024 11:25 am

Issue with SPI Driver in ESP-IDF Porting

Postby Sree23 » Fri Feb 02, 2024 11:49 am

Hello ESP32 Community,

I hope this message finds you well. I'm currently working on a project that involves porting code from Arduino to ESP-IDF, specifically dealing with the SPI driver. While the code works flawlessly on Arduino, I'm encountering unexpected behavior after porting it to ESP-IDF.
Additional Information:

ESP-IDF Version: v5.1.2
ESP32 Board Model: ESP32 FireBettle
Connections: connecting the adc(ad7606) via spi to ESP32

I've thoroughly reviewed the ESP-IDF documentation and forums but haven't been able to pinpoint the issue. Any insights or suggestions from the community would be highly appreciated.

Thank you in advance for your time and assistance.

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

Re: Issue with SPI Driver in ESP-IDF Porting

Postby ESP_Sprite » Sat Feb 03, 2024 8:33 am

Hard to say where you're going wrong without seeing your code, or knowing what unexpected behaviour you're getting. (At the moment, you're more or less going 'I'm trying to make a cake and I failed, what am I doing wrong?') You probably will not get a useful response unless you give us a lot more info.

Sree23
Posts: 3
Joined: Fri Feb 02, 2024 11:25 am

Re: Issue with SPI Driver in ESP-IDF Porting

Postby Sree23 » Wed Feb 07, 2024 10:12 am

Hello ESP32 Community,

I hope this message finds you well. I am currently in the process of porting Arduino code to ESP IDF for SPI communication with an AD7606 ADC. Unfortunately, I failed to include the relevant code in my initial post, for which I sincerely apologize. To rectify this, I have attached the necessary files:

ported_code.c: This file contains the code I have ported to ESP IDF.
arduino_code.cpp: This file is the original Arduino code I used as a reference for SPI communication with the AD7606 ADC.

Details of Porting:
In the process of porting the code, I have made the following adjustments:

Replaced Arduino SPI initialization with ESP IDF SPI initialization.
Substituted pinMode and digitalWrite functions with ESP IDF GPIO configuration and control functions.
Replaced timing functions (delay and delayMicroseconds) with esp_rom_delay_us for precise timing control.
Implemented necessary modifications to ensure compatibility with the ESP IDF environment.

Request for Assistance:
I understand the importance of providing code for better understanding and troubleshooting, and I apologize for the oversight in my initial post. I would be extremely grateful for any assistance or advice the community can offer based on the attached files. Your expertise and support in helping me successfully port this Arduino code to ESP IDF would be immensely valuable.

Thank you very much for your understanding and consideration.
Attachments
ported_Code.c
(3.3 KiB) Downloaded 130 times
ardunio_code.cpp
(951 Bytes) Downloaded 120 times

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

Re: Issue with SPI Driver in ESP-IDF Porting

Postby ESP_Sprite » Thu Feb 08, 2024 2:26 am

That helps a lot. Can you also elaborate on specifically what 'unexpected behaviour' you're getting?

Sree23
Posts: 3
Joined: Fri Feb 02, 2024 11:25 am

Re: Issue with SPI Driver in ESP-IDF Porting

Postby Sree23 » Mon Feb 12, 2024 6:00 am

Hello ESP community,

I'm encountering an issue with the ADC raw data in my ported ESP IDF code. I've ported the code from Arduino, where I successfully obtained the following ADC raw data:
Arduino ADC Raw Data:
1341 4046 1411 4051 1348 3997 1119 3721
1341 4054 1412 4059 1348 4003 1118 3725
1343 4055 1413 4060 1350 4001 1119 3729
1346 4053 1417 4064 1353 4001 1121 3731
1350 4053 1421 4067 1357 4001 1123 3736
1354 4051 1425 4069 1360 4002 1126 3740
1358 4052 1430 4072 1365 4004 1128 3747
However, when running the same procedure in my ESP IDF ported code, I'm getting different values:
ESP IDF Ported Code ADC Raw Data:

2133 256 311 2023 1949 267 326 1980
2131 250 310 2026 1944 265 326 1983
2130 249 310 2026 1944 266 326 1983
2134 252 312 2027 1944 268 329 1982
2130 266 315 2025 1945 271 332 1982
2134 289 321 2026 1947 279 337 1980
2129 260 322 2020 1932 276 340 1971

Observations:
1.The ADC raw data obtained from the ESP IDF ported code is significantly different from that of the Arduino code.
2.These discrepancies are consistent across multiple readings.
3. The code logic for obtaining ADC raw data has been ported directly from Arduino to ESP IDF.

Request for Assistance:
I would greatly appreciate any insights or suggestions on why this data mismatch might be occurring and how to rectify it. If anyone has experience with porting Arduino code to ESP IDF or has encountered similar issues before, your input would be invaluable.

Thank you in advance for your time and assistance.

Who is online

Users browsing this forum: Google [Bot] and 87 guests