Output mode for GPIO pins 12, 13, 14, 15 not working?

boilerbots
Posts: 4
Joined: Thu Aug 10, 2017 7:22 am

Output mode for GPIO pins 12, 13, 14, 15 not working?

Postby boilerbots » Thu Aug 10, 2017 7:34 am

I have configured 13 pins on my device to be GPIO_MODE_OUTPUT. I set the pull-up mode to FLOATING. I set the drive capability to MAX.

When I write to the set and clear registers or the data register all pins toggle except for pins 12-14.

I have tried every combination of modes and pull-ups and nothing makes this work. I used the special RTC functions to deregister these pins.

If I change the pull mode to up or down then the physical pin will change states. I even tried a brand new ESP-WROOM32 module because I thought perhaps there is a chance my first one could be defective.

I assume other people have tried all GPIO pins and they do work. My program is so simple, could the RTOS be doing something?

Here is an example of the program I am running to debug this:

Code: Select all

void app_main(void)
{
  nvs_flash_init();
  int xx;
  for (xx = 0; xx < GPIO_PIN_COUNT; xx++)
  {
    if (GPIO_IS_VALID_OUTPUT_GPIO(xx) && (xx < 6 || xx > 11))
    {
      gpio_set_direction(xx, GPIO_MODE_OUTPUT);  //Latch
    }
  }
  while(1)
  {    
      GPIO.out_w1ts = 0xFFFFFFFF;
      vTaskDelay(50 / portTICK_PERIOD_MS);
      GPIO.out_w1tc = 0xFFFFFFFF;
      vTaskDelay(50 / portTICK_PERIOD_MS);
    }
  }
}

ESP_igrr
Posts: 2071
Joined: Tue Dec 01, 2015 8:37 am

Re: Output mode for GPIO pins 12, 13, 14, 15 not working?

Postby ESP_igrr » Thu Aug 10, 2017 1:38 pm

At reset, these pins are configured for JTAG function. You need to change function back to GPIO in the IO MUX to make the pins work as GPIOs. If you use GPIO driver (include "driver/gpio.h", not "rom/gpio.h"), it will configure the pin as GPIO for you, once you call gpio_config to configure the pin.

boilerbots
Posts: 4
Joined: Thu Aug 10, 2017 7:22 am

Re: Output mode for GPIO pins 12, 13, 14, 15 not working?

Postby boilerbots » Fri Aug 11, 2017 5:17 am

Looks like the missing function call is this macro, put into my configuration loop:

Code: Select all

      PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[xx], PIN_FUNC_GPIO);
That puts the pins back into GPIO mode, or I can call gpio_config() and configure everything in one call.

Now I know the problem I tried to find this in the user manual and it is not obvious. In the on-line API document there is no mention, just that GPIO 6-11 are typically used for flash. The esp-wroom-32 datasheet only mention that these pins can be JTAG pins, and the ESP32 core board schematic also isn't helpful. The ESP32 tehcnical reference manual page 46 and 47 says that the "reset" state for each pin is an input pin but it also does not make it clear or obvious that these pins default to JTAG. I guess one could assume that this would be required for JTAG to even work but again it certainly isn't made obvious to where someone searching for this problem could find it in the document.When I look at Table 17, knowing what I now know, I would then imply that the pins default to the function in the "Function 1" column of the table after reset but maybe that isn't true for all the pins.

Anyway thanks for your help, I was stuck on this simple problem, glad I went to bed instead of pulling more hair out.

OutOfLine
Posts: 52
Joined: Sat Feb 24, 2018 1:32 pm

Re: Output mode for GPIO pins 12, 13, 14, 15 not working?

Postby OutOfLine » Sat Feb 24, 2018 6:05 pm

ESP32 is a wonderful beast, but sometimes I don't get it...

For a projet that has emerged out of an old Arduino project i need a lot of gpio outputs.

The project uses Arduino IDE
I have tried to simplify the code so you can spot why it is not working
The pins to test are stored in an array
they have LEDs connected

What is wrong with the following

Code: Select all

/*
  esp32_gpio_output_test.ino
  try to configure a couple of difficult gpio PINS to output
*/

#include "driver/gpio.h"

// number of hardware pins  connected to anything, like piezzos to click ;)
#define CLICK_PULSES	12

uint8_t click_pin[CLICK_PULSES] =
  {23, 5, 17, 16, 4, 2, 15,     32, 33, 27, 14, 13, };
  //  pins 2, 14, 32, 33 need configuration FIXME!

void init_click_pins_OutLow() {		// make them GPIO, OUTPUT, LOW
  // see http://wiki.ai-thinker.com/_media/esp32/docs/esp32_chip_pin_list_en.pdf

  int pin;
  for (int pulse=0; pulse<CLICK_PULSES; pulse++) {
    pin=click_pin[pulse];
    Serial.write("gpio init "); Serial.print(pin); Serial.write('\t');

    if (GPIO_IS_VALID_OUTPUT_GPIO(pin) && (pin < 6 || pin > 11)) {
      Serial.write("GPIO_IS_VALID_OUTPUT_GPIO\t");

      Serial.write("PIN_FUNC_SELECT(..., PIN_FUNC_GPIO)\t");
      PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[pin], PIN_FUNC_GPIO);

/* Some other code fragments I have tried
   no one helped on pins 2, 32, 33, 14

    // Serial.write("gpio_set_direction\t");
    // gpio_set_direction((gpio_num_t) pin, GPIO_MODE_OUTPUT);

    // Serial.write(gpio_pad_select_gpio );
    // gpio_pad_select_gpio(pin);

    switch (pin) {	// code fragments from tests on individual pins
    case 2:
      pinMode(pin, FUNCTION_3); 					// does not help
      // PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[GPIO_NUM_2], PIN_FUNC_GPIO);	// does not help
      break;
    case 14:
      // PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[GPIO_NUM_14], PIN_FUNC_GPIO);	// does not help
      pinMode(pin, FUNCTION_3); 	// does not help on ESP32, but does on *ESP8266*
      break;
    case 32:
      // https://github.com/espressif/esp-idf/issues/143 
      // gpio32 route to digital io_mux
      REG_CLR_BIT(RTC_IO_XTAL_32K_PAD_REG, RTC_IO_X32P_MUX_SEL);	// does not help
      // PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[GPIO_NUM_32], PIN_FUNC_GPIO);	// does not help
      // pinMode(pin, FUNCTION_3);				 	// does not help
      break;
    case 33:
      // https://github.com/espressif/esp-idf/issues/143 
      REG_CLR_BIT(RTC_IO_XTAL_32K_PAD_REG, RTC_IO_X32N_MUX_SEL);	// does not help
      // PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[GPIO_NUM_33], PIN_FUNC_GPIO);	// does not help
      // pinMode(pin, FUNCTION_3);				 	// does not help
      break;
    }
*/

    } else {
      Serial.write("invalid gpio for output\t");
      Serial.write(pin);
    }

    Serial.write("pinMode(pin, OUTPUT)\t");
    pinMode(pin, OUTPUT);

    Serial.println("digitalWrite(pin, LOW)");
    digitalWrite(pin, LOW);
  }

  gpio_config_t gpioConfig;
  gpioConfig.pin_bit_mask = (1 << 2) | (1 << 14) | (1 << 32) | (1 << 33);
  gpioConfig.mode = GPIO_MODE_OUTPUT;
  gpioConfig.pull_up_en = GPIO_PULLUP_DISABLE;
  gpioConfig.pull_down_en = GPIO_PULLDOWN_DISABLE;
  gpioConfig.intr_type = GPIO_INTR_DISABLE;

  Serial.println("gpio_config(&gpioConfig);");
  Serial.println();
  gpio_config(&gpioConfig);
}


void setup() {
  Serial.begin(115200);
  while (!Serial) { yield(); }		// wait for Serial to open

  init_click_pins_OutLow();
}


void loop() {
  for (int pulse=0; pulse<CLICK_PULSES; pulse++)
    digitalWrite(click_pin[pulse],HIGH);
  delay(1234);

  for (int pulse=0; pulse<CLICK_PULSES; pulse++)
    digitalWrite(click_pin[pulse],LOW);
  delay(1234);

  if (Serial.available()) {
    init_click_pins_OutLow();	// show output again
    while(Serial.available()) 
      Serial.read();
  }
}
As you can guess from all the unused code fragments I have tested for quite a while
still confused...

Help very much appreciated :)

Who is online

Users browsing this forum: No registered users and 59 guests