wiring analogWrite() function does not respect previously set pinMode() · Issue #7836 · esp8266/Arduino (original) (raw)

Basic Infos

Platform

Settings in IDE

Problem Description

The circuit I'm using the NodeMCU in requires PWM open-drain outputs. Even when setting the outputs to open-drain via pinMode(), passing OUTPUT_OPEN_DRAIN, the analogWrite() function resets the output to push-pull mode (OUTPUT).

The problem can be found in line 65 of the source file Arduino/cores/esp8266/core_esp8266_wiring_pwm.cpp (in the current master branch), where the pinMode() is reset to OUTPUT, regardless of what was previously set via this method.

To reproduce the problem, the sketch below can be run, with the output pin connected via a pull-down resistor (10k) to ground, and an oscilloscope connected to the output. The output should stay at 0V all the time (as pwm should either connect the output to GND, or leave it open, where the pull-down resistor would keep it at GND potential, if open-drain was respected). The observed output transitions between 0V and 3V3, as corresponds to a push-pull output configuration.

MCVE Sketch

#include <Arduino.h>

void setup() { pinMode(14, OUTPUT_OPEN_DRAIN); analogWrite(14, 128); }

void loop() { // Nothing needed here }

Debug Messages