Skip to content

wiring analogWrite() function does not respect previously set pinMode() #7836

Closed
@afdeprado

Description

@afdeprado

Basic Infos

  • [X ] This issue complies with the issue POLICY doc.
  • [X ] I have read the documentation at readthedocs and the issue is not addressed there.
  • [X ] I have tested that the issue is present in current master branch (aka latest git).
  • [X ] I have searched the issue tracker for a similar issue.
  • [X ] If there is a stack dump, I have decoded it.
  • [X ] I have filled out all fields below.

Platform

  • Hardware: [ESP-12E]
  • Core Version: [master branch and 2.7.4 (3.20704.0)]
  • Development Env: [Platformio]
  • Operating System: [Windows]

Settings in IDE

  • Module: [Nodemcu]
  • Flash Mode: [do not know - not relevant]
  • Flash Size: [4MB]
  • lwip Variant: [do not know - not relevant]
  • Reset Method: [nodemcu]
  • Flash Frequency: [do not know - not relevant]
  • CPU Frequency: [80Mhz]
  • Upload Using: [SERIAL]
  • Upload Speed: [115200] (serial upload only)

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

No debug messages

Metadata

Metadata

Assignees

No one assigned

    Labels

    waiting for feedbackWaiting on additional info. If it's not received, the issue may be closed.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions