[ESP32] Not Responding to Input Signal Connected to GPIO33

AJGembedded
Posts: 4
Joined: Fri Jun 18, 2021 1:05 am

[ESP32] Not Responding to Input Signal Connected to GPIO33

Postby AJGembedded » Sat Jun 19, 2021 4:53 am

I am actually using the registers directly using C, but using the ESP-IDF build system. Currently I have 5 momentary buttons connected directly to the GPIO with 10k ohm pull-down resistors.
The pushbuttons are connected as follows:
button0 (Red) GPIO32
button1 (Yellow) GPIO33
button2 (Green) GPIO12
button3 (Blue) GPIO13
button4 (Black) GPIO36

I am also using the Digilent Analog Discovery 2 with Waveforms application to verify my signals for the buttons. Each button has been verified to produce the correct signal based on pushing a button and releasing it. When I retrieve the data output from the GPIO_IN_REG and GPIO_IN1_REG as appropriate, I noticed that all button inputs except the yellow one had been processed. I know that the button color is immaterial, but it just seemed like it might be easier to identify them for this discussion. Just to verify that the jumper wires were connected properly, I momentarily tested the circuit using the internal pull-down resistors and removing the external pull-down resistors.

All IO_MUX registers for the 5 GPIO pins listed above have been configured to use GPIO function (3) and have been set with input enabled.
I made sure to clear bits 17 and 18 of the RTCIO_XTAL_32K_PAD_REG register which correspond to the XTAL_P and XTAL_N respectively to route the pads to the IO_MUX instead of the RTC according to the technical reference manual.

I seem to be at a loss as I am unable to find what is preventing the signal connected to the GPIO33 pin from reaching the GPIO_IN1_REG. I assumed that routing the XTAL_P and XTAL_N signals to the IO_MUX would have been enough. Does the community have a suggestion of what to try?

I also attempted to perform this using the built-in IDF libraries with the following code:
  1. #include <stdio.h>
  2. #include "driver/gpio.h"
  3. #include "driver/rtc_io.h"
  4. #include "esp_log.h"
  5. #include "freertos/FreeRTOS.h"
  6. #include "freertos/task.h"
  7. #include "freertos/timers.h"
  8.  
  9. const char *TAG = "Button";
  10.  
  11. uint16_t pressButtonRed,pressButtonYellow,pressButtonBlue,pressButtonGreen,pressButtonBlack;
  12.  
  13. IRAM_ATTR void button0_press(void* args)
  14. {
  15.   pressButtonRed++;
  16. }
  17.  
  18. IRAM_ATTR void button1_press(void* args)
  19. {
  20.   pressButtonYellow++;
  21. }
  22.  
  23. IRAM_ATTR void button2_press(void* args)
  24. {
  25.   pressButtonGreen++;
  26. }
  27.  
  28. IRAM_ATTR void button3_press(void* args)
  29. {
  30.   pressButtonBlue++;
  31. }
  32.  
  33. IRAM_ATTR void button4_press(void* args)
  34. {
  35.   pressButtonBlack++;
  36. }
  37.  
  38. static const char *stateButtonGreen = {"OFF"," ON"};
  39.  
  40. void read_buttons(TimerHandle_t pxTimer)
  41. {
  42.   ESP_LOGI(TAG,"Button0=%d, Button1=%d, Button2=%d, Button3=%d, Button4=%d",pressButtonRed,pressButtonYellow,pressButtonGreen,pressButtonBlue,pressButtonBlack);
  43. }
  44.  
  45.  
  46. void app_main(void)
  47. {
  48.   TimerHandle_t buttonTimerHandle; //handle for a debug timer
  49.   gpio_config_t cfgButtons = {
  50.     .pin_bit_mask = 0x1300003000,
  51.     .mode = GPIO_MODE_INPUT,
  52.     .pull_up_en = GPIO_PULLUP_DISABLE,
  53.     .pull_down_en = GPIO_PULLDOWN_DISABLE,
  54.     .intr_type = GPIO_INTR_POSEDGE
  55.   };
  56.  
  57.   ESP_LOGI(TAG,"Configuring the buttons");
  58.   gpio_config(&cfgButtons);
  59.   REG_CLR_BIT(RTC_IO_XTAL_32K_PAD_REG, RTC_IO_X32N_MUX_SEL);
  60.   REG_CLR_BIT(RTC_IO_XTAL_32K_PAD_REG, RTC_IO_X32P_MUX_SEL);
  61.   pressButtonRed = 0;
  62.   pressButtonYellow = 0;
  63.   pressButtonGreen = 0;
  64.   pressButtonBlue = 0;
  65.   pressButtonBlack = 0;
  66.  
  67.   gpio_install_isr_service(ESP_INTR_FLAG_IRAM |  ESP_INTR_FLAG_EDGE);
  68.   gpio_isr_handler_add(GPIO_NUM_32,button0_press,NULL);
  69.   gpio_isr_handler_add(GPIO_NUM_33,button1_press,NULL);
  70.   gpio_isr_handler_add(GPIO_NUM_12,button2_press,NULL);
  71.   gpio_isr_handler_add(GPIO_NUM_13,button3_press,NULL);
  72.   gpio_isr_handler_add(GPIO_NUM_36,button4_press,NULL);
  73.  
  74.   buttonTimerHandle = xTimerCreate("ButtonsTimer",pdMS_TO_TICKS( 1000 ),pdTRUE,NULL,read_buttons);
  75.   xTimerStart(buttonTimerHandle,0);
  76. }
  77. }
Pressing the red, green, blue and black buttons incremented their corresponding counters, however, pressing the yellow button did nothing.

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

Re: [ESP32] Not Responding to Input Signal Connected to GPIO33

Postby ESP_Sprite » Sun Jun 20, 2021 3:02 am

That is odd... gpio_config is supposed to already do everything needed to get a GPIO in the configured state, so you manually twiddling RTC_IO_X32N_MUX_SEL should not even be necessary... it almost feels like you have a hardware error; does GPIO33 work correctly if you configure it as an output and measure it?

AJGembedded
Posts: 4
Joined: Fri Jun 18, 2021 1:05 am

Re: [ESP32] Not Responding to Input Signal Connected to GPIO33

Postby AJGembedded » Mon Jun 21, 2021 6:28 pm

I revised using this code and GPIO33 is not updating when I press the other buttons
I have them set so that the Red and Blue buttons are supposed to turn on GPIO33, while Green and Black are supposed to turn off GPIO33 off. Connected the jumper wire directly to the logic analyzer for GPIO33. No changes have been made to the GPIO33 signal no matter what was pressed. I'd expect that pressing the Red or Blue buttons would make the signal go high, while the Black and Green buttons would make it go low.

Code: Select all

#include <stdio.h>
#include "driver/gpio.h"
#include "driver/rtc_io.h"
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/timers.h"

const char *TAG = "Button";

uint16_t pressButtonRed,pressButtonYellow,pressButtonBlue,pressButtonGreen,pressButtonBlack;

IRAM_ATTR void button0_press(void* args)
{
  pressButtonRed++;
  gpio_set_level(GPIO_NUM_33,1);
}

IRAM_ATTR void button1_press(void* args)
{
  pressButtonYellow++;
}

IRAM_ATTR void button2_press(void* args)
{
  pressButtonGreen++;
  gpio_set_level(GPIO_NUM_33,0);
}

IRAM_ATTR void button3_press(void* args)
{
  pressButtonBlue++;
  gpio_set_level(GPIO_NUM_33,1);
}

IRAM_ATTR void button4_press(void* args)
{
  pressButtonBlack++;
  gpio_set_level(GPIO_NUM_33,0);
}

static const char *stateButtonGreen[2] = {"OFF"," ON"};

void read_buttons(TimerHandle_t pxTimer)
{
  uint32_t status1 = gpio_get_level(GPIO_NUM_33);
  ESP_LOGI(TAG,"Button0=%d, Status1=%s, Button2=%d, Button3=%d, Button4=%d",pressButtonRed,(stateButtonGreen[status1]),pressButtonGreen,pressButtonBlue,pressButtonBlack);
}


void app_main(void)
{
  TimerHandle_t buttonTimerHandle; //handle for a debug timer
  gpio_config_t cfgButtons = {
    .pin_bit_mask = 0x1100003000,
    .mode = GPIO_MODE_INPUT,
    .pull_up_en = GPIO_PULLUP_DISABLE,
    .pull_down_en = GPIO_PULLDOWN_DISABLE,
    .intr_type = GPIO_INTR_POSEDGE
  };
  
  ESP_LOGI(TAG,"Configuring the buttons");
  gpio_config(&cfgButtons);
  
  ESP_LOGI(TAG,"Setting GPIO33 to output");
  gpio_set_direction(GPIO_NUM_33,GPIO_MODE_OUTPUT);
  gpio_intr_disable(GPIO_NUM_33);
  REG_CLR_BIT(RTC_IO_XTAL_32K_PAD_REG, RTC_IO_X32N_MUX_SEL);
  REG_CLR_BIT(RTC_IO_XTAL_32K_PAD_REG, RTC_IO_X32P_MUX_SEL);
  pressButtonRed = 0;
  pressButtonYellow = 0;
  pressButtonGreen = 0;
  pressButtonBlue = 0;
  pressButtonBlack = 0;
  
  gpio_install_isr_service(ESP_INTR_FLAG_IRAM |  ESP_INTR_FLAG_EDGE);
  gpio_isr_handler_add(GPIO_NUM_32,button0_press,NULL);
 // gpio_isr_handler_add(GPIO_NUM_33,button1_press,NULL);
  gpio_isr_handler_add(GPIO_NUM_12,button2_press,NULL);
  gpio_isr_handler_add(GPIO_NUM_13,button3_press,NULL);
  gpio_isr_handler_add(GPIO_NUM_36,button4_press,NULL);
  
  buttonTimerHandle = xTimerCreate("ButtonsTimer",pdMS_TO_TICKS( 1000 ),pdTRUE,NULL,read_buttons);
  xTimerStart(buttonTimerHandle,0);
}
Last edited by AJGembedded on Thu Jul 01, 2021 5:37 am, edited 1 time in total.

AJGembedded
Posts: 4
Joined: Fri Jun 18, 2021 1:05 am

Re: [ESP32] Not Responding to Input Signal Connected to GPIO33

Postby AJGembedded » Mon Jun 21, 2021 6:33 pm

This was purchased from SparkFun as a part of the "SparkFun Thing Plus - ESP32 U.FL"
I already noticed certain other issues regarding I2C and SPI that I have puzzled me and considered trying to write to the registers instead of using the API given the signals did not seem to be working as exprected. I assumed that before the RTS and CTS signals from the UART were interfering with my use of the other pins for the other protocols.... but perhaps this could indeed be a hardware error all tied together...
ESP_Sprite wrote:
Sun Jun 20, 2021 3:02 am
That is odd... gpio_config is supposed to already do everything needed to get a GPIO in the configured state, so you manually twiddling RTC_IO_X32N_MUX_SEL should not even be necessary... it almost feels like you have a hardware error; does GPIO33 work correctly if you configure it as an output and measure it?

AJGembedded
Posts: 4
Joined: Fri Jun 18, 2021 1:05 am

Re: [ESP32] Not Responding to Input Signal Connected to GPIO33

Postby AJGembedded » Wed Jun 30, 2021 9:47 pm

After some further testing, it has been discovered that GPIO33 will intermittently respond. Is there something else that I can try configuring to ensure that it reliably works?

Who is online

Users browsing this forum: No registered users and 135 guests