Unpredictable GPIO inputs behavior
Posted: Thu Dec 07, 2023 12:06 pm
Hi,
I am developing a product that includes using fast ADC with ESP32 (I am using Ethernet kit board with WROOVER - E model). I am using ADC12020 which has 12 bit parallel outputs. I am aiming for sample frequency above 1 MSPS so, gpio_get/set_level commands does not do it for me (I developed a parallel gpio read code, also I am generating the clock for the ADC with my ESP gpio output using low level commands)... I am getting very strange readings, and ADC has nothing to do with it this time...
For the testing, I physically disconnect everything from the ESP board and I enable the pull-down resistors in the setup. However, I still get unexplainable readings of 2699 every cycle... (this translates to 1010 1000 1011 reading from MSB to LSB, but even my multimeter shows, that every single pin is at 0 volts.) Just for clarification, I have increased the watchdog timer interval to 11000 ms in the menuconfig, I dont know if this makes any difference, but other than that I have absolutely no clue what the problem could be...
I am aware that some pins have reserved functions, but I only use the pins that are routed to the devboard pin headers, I guess its extremely unlikely for the manufacturer to put such pins in the pin header row...
Any ideas what could be causing this mad behavior of GPIO?
logs:
Cycle 1: 2699
Cycle 2: 2699
Cycle 3: 2699
Cycle 4: 2699
Cycle 5: 2699
Cycle 6: 2699
Cycle 7: 2699
Cycle 8: 2699
Cycle 9: 2699
Cycle 10: 2699
Cycle 11: 2699
Cycle 12: 2699
Cycle 13: 2699
Cycle 14: 2699
Cycle 15: 2699
Cycle 16: 2699
Cycle 17: 2699
Cycle 18: 2699
Cycle 19: 2699
Cycle 20: 2699
Cycle 21: 2699
Cycle 22: 2699
Cycle 23: 2699
Cycle 24: 2699
Cycle 25: 2699
Cycle 26: 2699
Cycle 27: 2699
Cycle 28: 2699
Cycle 29: 2699
Cycle 30: 2699
Cycle 31: 2699
Cycle 32: 2699
Cycle 33: 2699
Cycle 34: 2699
Cycle 35: 2699
Cycle 36: 2699
Cycle 37: 2699
Cycle 38: 2699
Cycle 39: 2699
Cycle 40: 2699
Cycle 41: 2699
Cycle 42: 2699
Cycle 43: 2699
Cycle 44: 2699
Cycle 45: 2699
Cycle 46: 2699
Cycle 47: 2699
Cycle 48: 2699
Cycle 49: 2699
Cycle 50: 2699
Cycle 51: 2699
Cycle 52: 2699
Cycle 53: 2699
Cycle 54: 2699
Cycle 55: 2699
Cycle 56: 2699
Cycle 57: 2699
Cycle 58: 2699
Cycle 59: 2699
Cycle 60: 2699
Cycle 61: 2699
Cycle 62: 2699
Cycle 63: 2699
Cycle 64: 2699
Cycle 65: 2699
Cycle 66: 2699
Cycle 67: 2699
Cycle 68: 2699
Cycle 69: 2699
Cycle 70: 2699
Cycle 71: 2699
Cycle 72: 2699
Cycle 73: 2699
Cycle 74: 2699
Cycle 75: 2699
Cycle 76: 2699
Cycle 77: 2699
Cycle 78: 2699
Cycle 79: 2699
Cycle 80: 2699
Cycle 81: 2699
Cycle 82: 2699
Cycle 83: 2699
Cycle 84: 2699
Cycle 85: 2699
Cycle 86: 2699
Cycle 87: 2699
Cycle 88: 2699
Cycle 89: 2699
Cycle 90: 2699
Cycle 91: 2699
Cycle 92: 2699
Cycle 93: 2699
Cycle 94: 2699
Cycle 95: 2699
Cycle 96: 2699
Cycle 97: 2699
Cycle 98: 2699
Cycle 99: 2699
Cycle 100: 2699
-----------------------------------------------------------
I am developing a product that includes using fast ADC with ESP32 (I am using Ethernet kit board with WROOVER - E model). I am using ADC12020 which has 12 bit parallel outputs. I am aiming for sample frequency above 1 MSPS so, gpio_get/set_level commands does not do it for me (I developed a parallel gpio read code, also I am generating the clock for the ADC with my ESP gpio output using low level commands)... I am getting very strange readings, and ADC has nothing to do with it this time...
For the testing, I physically disconnect everything from the ESP board and I enable the pull-down resistors in the setup. However, I still get unexplainable readings of 2699 every cycle... (this translates to 1010 1000 1011 reading from MSB to LSB, but even my multimeter shows, that every single pin is at 0 volts.) Just for clarification, I have increased the watchdog timer interval to 11000 ms in the menuconfig, I dont know if this makes any difference, but other than that I have absolutely no clue what the problem could be...
I am aware that some pins have reserved functions, but I only use the pins that are routed to the devboard pin headers, I guess its extremely unlikely for the manufacturer to put such pins in the pin header row...
Any ideas what could be causing this mad behavior of GPIO?
Code: Select all
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "driver/gpio.h"
#include "soc/soc.h"
#include "soc/gpio_struct.h"
#include "soc/gpio_reg.h"
#include "esp32/rom/ets_sys.h"
#include "soc/rtc.h"
#define INTERRUPT_INPUT 15
#define GPIO_CLOCK 14
#define NUM_GPIO_PINS 12
#define NUM_CYCLES 100
#define GPIO_PIN_12 12 //LSB
#define GPIO_PIN_13 13
#define GPIO_PIN_2 2
#define GPIO_PIN_4 4
#define GPIO_PIN_16 16
#define GPIO_PIN_17 17
#define GPIO_PIN_32 32
#define GPIO_PIN_33 33
#define GPIO_PIN_34 34
#define GPIO_PIN_35 35
#define GPIO_PIN_36 36
#define GPIO_PIN_39 39 //MSB
const uint32_t gpio_pins[NUM_GPIO_PINS] = {
12, 13, 2, 4, 16, 17, 32, 33, 34, 35, 36, 39
};
static const gpio_num_t GPIO_PINS[NUM_GPIO_PINS] = {
GPIO_PIN_12, GPIO_PIN_13, GPIO_PIN_2, GPIO_PIN_4,
GPIO_PIN_16, GPIO_PIN_17, GPIO_PIN_32, GPIO_PIN_33,
GPIO_PIN_34, GPIO_PIN_35, GPIO_PIN_36, GPIO_PIN_39
};
bool trigger = false;
uint16_t data_array[NUM_CYCLES] = {0};
static void IRAM_ATTR gpio_interrupt_handler(void *args)
{
trigger = true;
}
void disableWatchdog()
{
WRITE_PERI_REG(RTC_CNTL_WDTCONFIG0_REG, 0);
WRITE_PERI_REG(RTC_CNTL_WDTCONFIG1_REG, 0);
}
void app_main()
{
vTaskDelay(1000 / portTICK_PERIOD_MS);
esp_rom_gpio_pad_select_gpio(INTERRUPT_INPUT);
gpio_set_direction(INTERRUPT_INPUT, GPIO_MODE_INPUT);
gpio_pulldown_en(INTERRUPT_INPUT);
gpio_pullup_dis(INTERRUPT_INPUT);
gpio_set_intr_type(INTERRUPT_INPUT, GPIO_INTR_POSEDGE);
gpio_install_isr_service(0);
gpio_isr_handler_add(INTERRUPT_INPUT, gpio_interrupt_handler, (void *)INTERRUPT_INPUT);
gpio_config_t io_conf_output = {
.pin_bit_mask = (1ULL << GPIO_CLOCK),
.mode = GPIO_MODE_OUTPUT,
};
gpio_config(&io_conf_output);
gpio_config_t io_conf;
for (int i = 0; i < NUM_GPIO_PINS; ++i)
{
io_conf = (gpio_config_t){
.pin_bit_mask = (1ULL << GPIO_PINS[i]),
.mode = GPIO_MODE_INPUT,
.intr_type = GPIO_INTR_DISABLE,
.pull_up_en = GPIO_PULLUP_DISABLE,
.pull_down_en = GPIO_PULLDOWN_ENABLE, // Enable pulldown resistors
};
gpio_config(&io_conf);
}
uint16_t gpio_inputs;
disableWatchdog();
int k = 0;
while (1)
{
REG_WRITE(GPIO_OUT_W1TS_REG, (1 << GPIO_CLOCK));
gpio_inputs |= (REG_READ(GPIO_IN_REG) >> GPIO_PIN_12) & 0x3F;
REG_WRITE(GPIO_OUT_W1TC_REG, (1 << GPIO_CLOCK));
gpio_inputs |= ((REG_READ(GPIO_IN_REG) >> GPIO_PIN_32) & 0x3F) << 6;
if (trigger)
{
for (; k < NUM_CYCLES; k++)
{
REG_WRITE(GPIO_OUT_W1TS_REG, (1 << GPIO_CLOCK));
data_array[k] = REG_READ(GPIO_IN_REG) & ((1ULL << NUM_GPIO_PINS) - 1);
//Block bellow is noly for debugging
printf("GPIO Pin 12: %d\n", gpio_get_level(GPIO_PIN_12));
printf("GPIO Pin 13: %d\n", gpio_get_level(GPIO_PIN_13));
printf("GPIO Pin 2: %d\n", gpio_get_level(GPIO_PIN_2));
printf("GPIO Pin 4: %d\n", gpio_get_level(GPIO_PIN_4));
printf("GPIO Pin 16: %d\n", gpio_get_level(GPIO_PIN_16));
printf("GPIO Pin 17: %d\n", gpio_get_level(GPIO_PIN_17));
printf("GPIO Pin 32: %d\n", gpio_get_level(GPIO_PIN_32));
printf("GPIO Pin 33: %d\n", gpio_get_level(GPIO_PIN_33));
printf("GPIO Pin 34: %d\n", gpio_get_level(GPIO_PIN_34));
printf("GPIO Pin 35: %d\n", gpio_get_level(GPIO_PIN_35));
printf("GPIO Pin 36: %d\n", gpio_get_level(GPIO_PIN_36));
printf("GPIO Pin 39: %d\n", gpio_get_level(GPIO_PIN_39));
printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
REG_WRITE(GPIO_OUT_W1TC_REG, (1 << GPIO_CLOCK));
}
k = 0;
for (; k < NUM_CYCLES; k++)
{
printf("Cycle %d: %d\n", k + 1, data_array[k]);
}
printf("-----------------------------------------------------------\n");
memset(data_array, 0, sizeof(data_array));
k = 0;
trigger = false;
}
}
}
Cycle 1: 2699
Cycle 2: 2699
Cycle 3: 2699
Cycle 4: 2699
Cycle 5: 2699
Cycle 6: 2699
Cycle 7: 2699
Cycle 8: 2699
Cycle 9: 2699
Cycle 10: 2699
Cycle 11: 2699
Cycle 12: 2699
Cycle 13: 2699
Cycle 14: 2699
Cycle 15: 2699
Cycle 16: 2699
Cycle 17: 2699
Cycle 18: 2699
Cycle 19: 2699
Cycle 20: 2699
Cycle 21: 2699
Cycle 22: 2699
Cycle 23: 2699
Cycle 24: 2699
Cycle 25: 2699
Cycle 26: 2699
Cycle 27: 2699
Cycle 28: 2699
Cycle 29: 2699
Cycle 30: 2699
Cycle 31: 2699
Cycle 32: 2699
Cycle 33: 2699
Cycle 34: 2699
Cycle 35: 2699
Cycle 36: 2699
Cycle 37: 2699
Cycle 38: 2699
Cycle 39: 2699
Cycle 40: 2699
Cycle 41: 2699
Cycle 42: 2699
Cycle 43: 2699
Cycle 44: 2699
Cycle 45: 2699
Cycle 46: 2699
Cycle 47: 2699
Cycle 48: 2699
Cycle 49: 2699
Cycle 50: 2699
Cycle 51: 2699
Cycle 52: 2699
Cycle 53: 2699
Cycle 54: 2699
Cycle 55: 2699
Cycle 56: 2699
Cycle 57: 2699
Cycle 58: 2699
Cycle 59: 2699
Cycle 60: 2699
Cycle 61: 2699
Cycle 62: 2699
Cycle 63: 2699
Cycle 64: 2699
Cycle 65: 2699
Cycle 66: 2699
Cycle 67: 2699
Cycle 68: 2699
Cycle 69: 2699
Cycle 70: 2699
Cycle 71: 2699
Cycle 72: 2699
Cycle 73: 2699
Cycle 74: 2699
Cycle 75: 2699
Cycle 76: 2699
Cycle 77: 2699
Cycle 78: 2699
Cycle 79: 2699
Cycle 80: 2699
Cycle 81: 2699
Cycle 82: 2699
Cycle 83: 2699
Cycle 84: 2699
Cycle 85: 2699
Cycle 86: 2699
Cycle 87: 2699
Cycle 88: 2699
Cycle 89: 2699
Cycle 90: 2699
Cycle 91: 2699
Cycle 92: 2699
Cycle 93: 2699
Cycle 94: 2699
Cycle 95: 2699
Cycle 96: 2699
Cycle 97: 2699
Cycle 98: 2699
Cycle 99: 2699
Cycle 100: 2699
-----------------------------------------------------------