Connecting transistor to pin D9 (MISO) in XIAO ESP32C3 makes that the board cannot start correctly

Hi everyone,

I’ve been trying to control a relay through a transistor, which is connected to the GPIO09 (MISO). I have programmed the board with different examples and platforms (Arduino, ESP Home) and always get the same problem.

As soon as the pin is connected to the base of the NPN transistor, the board cannot start. I’m using a basic circuit. A resistor (1K) in series to the GPIO09 and this is connected to the base of the transistor. The collector of the transistor is connected to the relay and in parallel there is a diode (1N4148), the emitter of the transistor is connected to ground.

When I disconnect the transistor or remove the resistor, the board is back again (after I repower the board and press the reset button).

I have modified the circuit to look for different solutions, but I was not able to succeed.

  • Connect a resistor between the base of the transistor and ground (18K)
  • Use different transistor

Any idea?

did you try another pin?

Yes, i did it, and it works. But i already made a pcb with the GPIO09. This is why I’d like to understand why that pin doesn’t work

D9 is a STRAP pin and must be HIGH when powered on. According to the schematic, D9 is pulled up with 10k and connected to the BOOT switch. The design must be such that D9 is HIGH at power-on, and also such that no problem will occur in the relay circuit no matter when the BOOT button is pressed. FETs might be suitable.
After power-on, it can be used as a normal GPIO.

1 Like

MISO is a fast communication bus… you should avoid these “Standard” pins for generic IO

Hi there,

Don’t use GPIO 9 like that, better to not use the Strapping pins.
Check the Technical Reference guide, using GPIO 9 especially in certain combination’s can cause the MCU to be Unstable and Unpredictable.
From the datasheet…

2.4 Strapping Pins

ESP32-C3 has three strapping pins:
• GPIO2
• GPIO8
• GPIO9
Software can read the values of GPIO2, GPIO8 and GPIO9 from GPIO_STRAPPING field in GPIO_STRAP_REG
register. For register description, please refer to Section GPIO Matrix Register Summary in
ESP32-C3 Technical Reference Manual.
During the chip’s system reset, the latches of the strapping pins sample the voltage level as strapping bits of ”0” or ”1”, and hold these bits until the chip is powered down or shut down.

Types of system reset include:
• power-on reset
• RTC watchdog reset
• brownout reset
• analog super watchdog reset
• crystal clock glitch detection reset

By default, GPIO9 is connected to the internal weak pull-up resistor. If GPIO9 is not connected or connected to an external high-impedance circuit,
the latched bit value will be ”1”

Espressif Systems 14 ESP32-C3 Series Datasheet v1.2

HTH
GL :slight_smile: PJ :v:

1 Like

Thanks guys, for your support.

It was interesting to know about the strapping pins and the weak pull-up resistor connected to GPIO9. I read a bit about this topic, and I realized that by increasing the base resistor of the transistor, I can reach kind of “high impedance circuit”. With a resistor of 3k3, the ESP module is able to start correctly. However, I need to check if the resistor is small enough to operate the transistor as on-off switch.

for msfujino, a tried to connect the D9 to HIGH but it doesn’t solve the problem.

2 Likes

The diagram below is my idea. In order to have both relay circuit and Strap function, you need to use NMOS.

1 Like

Nice Diagram! Hope it solves the problem… I still say move to another pin… you just picked the wrong one to start with!

Hi there, SO just to put a BOW on this…

His choices are kinda clear but Idunno, I can see it though , with so few pins sometimes you just need to RTFM and go for it, They do say it is possible and the Nmos FET @msfujino suggest is the way to accomplish it.

Here is what I found…
Using “strapping pins” like GPIO9 on the ESP32C3 as regular I/O pins after boot is possible, but you need to carefully consider their role during boot and ensure that your application does not conflict with their strapping function. Here’s how you can use GPIO9 and similar pins as I/O after boot:

1. Understanding GPIO9’s Strapping Role

  • GPIO9 on the ESP32C3 is one of the strapping pins that determines the boot mode during power-on reset.
  • Specifically, GPIO9 is used to configure the JTAG_SEL (JTAG mode selection).
  • The state of GPIO9 during boot (high or low) affects how the chip initializes, but after boot, it can be used as a regular GPIO pin.

2. Using GPIO9 as an I/O Pin

To safely use GPIO9 as a regular I/O pin:

Step 1: Set the Desired Boot State

  • Ensure GPIO9 is configured in the correct state (high or low) during boot for your application.
  • For example:
    • If using a pull-up resistor, GPIO9 will default to HIGH at boot.
    • If using a pull-down resistor, GPIO9 will default to LOW at boot.

Step 2: Reconfigure GPIO9 in Your Code

Once the ESP32C3 has booted, you can reconfigure GPIO9 for your desired use as an input or output pin in your application. Here’s an example:

void setup() {
  // Reconfigure GPIO9 as an output pin
  pinMode(9, OUTPUT);

  // Set GPIO9 to a known state
  digitalWrite(9, LOW); // Example: Set pin LOW
}

void loop() {
  // Toggle GPIO9
  digitalWrite(9, HIGH);
  delay(500);
  digitalWrite(9, LOW);
  delay(500);
}

Step 3: Handle Pull-Up/Down Resistors

  • If GPIO9 is externally connected to a pull-up or pull-down resistor (for strapping purposes), consider its effect during normal operation.
    * You may need to disable internal pull-up/down resistors in your firmware.

3. Important Notes

  • Boot Conflict Risk: During boot, the strapping pin’s state may momentarily interfere with your intended application logic.
  • External Resistors: If you’re using external resistors for boot strapping, ensure they don’t conflict with the intended GPIO usage during runtime.
  • Voltage Tolerances: Avoid applying voltages that could affect the strapping pin’s logic level during boot.

4. Debugging Tips

If GPIO9 doesn’t behave as expected:

  • Check the Boot Log: Confirm that the chip boots correctly with the chosen strapping pin state.
  • Verify Circuit Design: Ensure no unintended voltage is applied to GPIO9 during power-on.
  • Revisit Configuration: Double-check that GPIO9 is explicitly reconfigured as a regular GPIO pin in your code.

Example Use Case

For instance, if you want GPIO9 to drive an LED:

  1. Connect the LED and a resistor to GPIO9.
  2. Use a pull-up resistor for strapping to boot normally.
  3. After boot, reconfigure GPIO9 as an output and toggle it to drive the LED.
    That should lull you to Sleep … :smile: :v:

GL :slight_smile: PJ :+1:

Bonus tip, USE the Arduino IDE Tools menu to turn ON the Debugging level :hammer: