-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Incorrect value for OUTPUT_OPEN_DRAIN in esp32-hal-gpio.h #8590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@TMSL I assume that it's right to be 0x12, as the pin should be only OUTPUT_OPEN_DRAIN and not INPUT_OUTPUT_OPEN_DRAIN as you use it. If you want to read the pin you have to call |
Closing this as duplicate of #7022. |
When the definition of OUTPUT was changed to 0x03 from 0x02 (per comment in .h file), it implicitly made OUTPUT set the pin to INPUT at the same time. (since INPUT is defined as 0x01 and the settings are treated as OR'd together). But when the OUTPUT was changed to 0x03, the same automatically setting INPUT behavior was NOT added to the OUTPUT_OPEN_DRAIN definition. The problem with OUTPUT_OPEN_DRAIN being 0x12 is that it FAILS (because the code does not configure an output unless the value for INPUT is also SET). I.e. using pinmode with OUTPUT simultaneously sets INPUT, but using OUTPUT_OPEN_DRAIN in pinmode does not. There are two ways get an OPEN DRAIN output to work: Either you need to use OUTPUT_OPEN_DRAIN | INPUT ( per issue #7022 ) or you need to use OUTPUT | OPEN_DRAIN (per #8590). But, again, unlike OUTPUT, using OUTPUT_OPEN_DRAIN (0x12) BY ITSELF DOES NOT WORK. Only something that produces 0x13 does. |
@TMSL Sorry about closing it that fast. My bad. I will try to do some tests today, so from what you wrote, the output_opendrain is not working at all? Or what exactly is not working? I can open a PR with the fix you suggested today, if it's reasonable to get in into 2.0.12 release. |
Thanks. Yes, when I used OUTPUT_OPEN_DRAIN alone I got no output signal from the GPIO pin at all, even though I had a pullup resistor connected. When I used OUTPUT it worked fine as a driven signal. When I changed the code to OUTPUT | OPEN_DRAIN it worked and I verifed that it was operating as OPEN_DRAIN by seeing the signal go away when I removed the pullup. |
@TMSL Can you please post how you wired the pull-up and the LED to the GPIO? Thanks |
@TMSL I have tested driving an LED without the timer, using just simple loop. It works the same when I used I got the LED flashing in both settings, only with 0x13 I am able to read the output pin. SKETCH:
LOG using
LOG using
So from that the open drain works fine when used the |
THANKS AGAIN!! I see my issue. I had copied code from an example that toggled the GPIO using: DigitalWrite(OUTPIN, !DigitalRead(OUTPIN)); I also see that Arduino (e.g. for Atmega328p) only defines INPUT, OUTPUT, and INPUT_PULLUP in Arduino.h. I believe all other GPIO functions in esp32-hal-gpio.h are ESP-specific. I'M NOT REQUESTING ANY MORE CHANGES or re-opening of this issue, but just noting my understanding of the present bit definitions: //GPIO FUNCTIONS I think another ESP-specific definitions are also possible: For what it's worth, 0x01, 0x02, 0x04, 0x08 and 0x10 appear to be defined for use as bits to be OR'd together, where: //FUNCTIONS: // Individual ENABLE (ESP): |
I think my last comment was hard to read. This should be better:
For what it's worth, 0x01, 0x02, 0x04, 0x08 and 0x10 appear to be defined for use as bits to be OR'd together, where:
|
final version:
|
Board
ESP32S3 Dev Kit C
Device Description
It appears OUTPUT_OPEN_DRAIN should be 0x13 instead of 0x12.
In ESP32-hal-gpio.h:
//GPIO FUNCTIONS
#define INPUT 0x01
// Changed OUTPUT from 0x02 to behave the same as Arduino pinMode(pin,OUTPUT)
// where you can read the state of pin even when it is set as OUTPUT
#define OUTPUT 0x03 <=== OUTPUT
#define PULLUP 0x04
#define INPUT_PULLUP 0x05
#define PULLDOWN 0x08
#define INPUT_PULLDOWN 0x09
#define OPEN_DRAIN 0x10 <=== OPEN_DRAIN
#define OUTPUT_OPEN_DRAIN 0x12 <=== should be 0x13
#define ANALOG 0xC0
Hardware Configuration
tested with pullup resistor on gpio 38
Version
v2.0.11
IDE Name
Arduino 2.2.0
Operating System
Linux Mint
Flash frequency
80 MHz
PSRAM enabled
yes
Upload speed
115200
Description
Setting "OUTPUT_OPEN_DRAIN (= 0x12)" in pinmode does not work, but using OUTPUT | OPEN_DRAIN ( = 0x13) does.
Sketch
Debug Message
Other Steps to Reproduce
none
I have checked existing issues, online documentation and the Troubleshooting Guide
The text was updated successfully, but these errors were encountered: