Interal Pulldown not working on GPIO19?

sircastor
Posts: 7
Joined: Thu Nov 03, 2022 3:46 pm

Interal Pulldown not working on GPIO19?

Postby sircastor » Thu Nov 03, 2022 4:45 pm

Hello all,

I'm working on a project with an ESP32-C3-DevKit-M1, where I'm using GPIO19 for an input button. My design had the button connected to GPIO19 and VCC (3.3v from module).

Code: Select all

#define rightButtonPin 19
#define leftButtonPin 2

void setup() {

  pinMode(rightButtonPin, INPUT_PULLDOWN);
  pinMode(leftButtonPin, INPUT_PULLDOWN);

And while everything works with another button (GPIO2 - leftButtonPin) nothing was happening when I pressed the right button. If I rewire everything to go the opposite direction - using the internal pull up and having the button connect at GND signal - everything works fine.

The ESP32-C3 documentation says that all the GPIO pins have both internal pull-up and pull-down resistors, but I cannot get the internal pull-down resistor to activate. It works fine on other pins (such as GPIO18, for instance). I swapped out the module to make sure I wasn't dealing with bad hardware. Am I doing something wrong? Is there something special about GPIO19 that is not allowing it to set a Pull-down resistor?

thanks

felmue
Posts: 70
Joined: Mon Nov 16, 2020 2:55 pm

Re: Interal Pulldown not working on GPIO19?

Postby felmue » Fri Nov 04, 2022 7:07 am

Hello @sircastor

from the ESP32C3 datasheet: https://www.espressif.com/sites/default ... eet_en.pdf

USB - GPIO18 and GPIO19 are USB pins. The pull-up value of a USB pin is controlled by the pin’s pull-up
value together with USB pull-up value. If any of the two pull-up values is 1, the pin’s pull-up resistor will be
enabled. The pull-up resistors of USB pins are controlled by USB_SERIAL_JTAG_DP_PULLUP bit


How USB_SERIAL_JTAG_DP_PULLUP is controlled from Arduino I do not know though, sorry.

Thanks
Felix

sircastor
Posts: 7
Joined: Thu Nov 03, 2022 3:46 pm

Re: Interal Pulldown not working on GPIO19?

Postby sircastor » Fri Nov 04, 2022 7:28 am

Thanks Felix,

You can include ESP library headers in Arduino and they will reference the code library.

I have attempted to clear the appropriate flag, without success. This code tries to display the pulldown bit and then set it, and display it again, but it doesn't seem to set when I try to do so.

Code: Select all

Serial.print("Get USB_SERIAL_JTAG_PULL_DP_DOWN: ");
  Serial.println(REG_GET_BIT(USB_SERIAL_JTAG_EP1_REG, USB_SERIAL_JTAG_DP_PULLDOWN));
  
  REG_SET_BIT(USB_SERIAL_JTAG_EP1_REG, USB_SERIAL_JTAG_DP_PULLDOWN);

  Serial.print("Now, USB_SERIAL_JTAG_PULL_DP_DOWN: ");
  Serial.println(REG_GET_BIT(USB_SERIAL_JTAG_EP1_REG, USB_SERIAL_JTAG_DP_PULLDOWN)); 

Interestingly, I've also tried to just print out the whole of the register, to see if I could tell what other flags were set in USB_SERIAL_JTAG_EP1_REG, but unfortunately the whole byte was blank :cry:

savage
Posts: 23
Joined: Mon Jul 15, 2019 9:24 pm

Re: Interal Pulldown not working on GPIO19?

Postby savage » Mon Nov 07, 2022 2:50 pm

The header block and pin layout description for the ESP32-C3-DevKitM-1 suggests that GPIO19 is connected to D+, which is connected to the CP2102N USB-UART bridge, which may have its own pullup for that line (unclear from the CP2102N documentation). If that is the case, the pulldown on the ESP32-C3 would be fighting CP2102N's pullup.

However, the ESP32-C3-DevKitM-1 schematics shows the 0 Ohm resistor connecting GPIO19 to D+ as (NC), so those lines might not be tied together as the other documentation implies and the CP2102N will have no impact on GPIO19. In which case, this post is entirely unhelpful. ;)

sircastor
Posts: 7
Joined: Thu Nov 03, 2022 3:46 pm

Re: Interal Pulldown not working on GPIO19?

Postby sircastor » Sat Dec 03, 2022 5:25 pm

On the ESP32-C3-Mini-DevKitM1 page, there's a diagram that notes that pin 19 has a weak USB pullup, though I don't believe it's related to the CP2101. That led me to another forum post (https://esp32.com/viewtopic.php?t=27210) that mentioned that the pullup on GPIO19 has a number of bits on it that may set it.

Anyway, in order to set it on Arduino, I had to make sure it cleared it after I setup my inputs, like so:

Code: Select all

#include "/Users/username/Library/Arduino15/packages/esp32/hardware/esp32/2.0.5/tools/sdk/esp32c3/include/soc/esp32c3/include/soc/usb_serial_jtag_reg.h"

#define leftButtonPin 2
#define rightButtonPin 19

void setup() {
  // put your setup code here, to run once:
  pinMode(leftButtonPin, INPUT_PULLDOWN);
  pinMode(rightButtonPin, INPUT_PULLDOWN);
  CLEAR_PERI_REG_MASK(USB_SERIAL_JTAG_CONF0_REG, USB_SERIAL_JTAG_DP_PULLUP);
...
Also note I had to include the header for the mask so it knew what I was talking about. I hope that helps someone in the future.

(Edit: I had previously pasted code that cleared the USB_SERIAL_JTAG_USB_PAD_ENABLE bit, which is the wrong one.)

Who is online

Users browsing this forum: No registered users and 64 guests