8000 Reading the value of an output pin behaves differently in ESP32S2 than in SAMD · Issue #3353 · adafruit/circuitpython · GitHub
[go: up one dir, main page]

Skip to content

Reading the value of an output pin behaves differently in ESP32S2 than in SAMD #3353

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

Closed
anecdata opened this issue Aug 30, 2020 · 2 comments · Fixed by #3495
Closed

Reading the value of an output pin behaves differently in ESP32S2 than in SAMD #3353

anecdata opened this issue Aug 30, 2020 · 2 comments · Fixed by #3495
Labels
bug espressif applies to multiple Espressif chips good first issue

Comments

@anecdata
Copy link
Member
anecdata commented Aug 30, 2020

Is this a bug, or is it explicitly undefined behavior to read the value of an output?

>>> import board
>>> from digitalio import DigitalInOut, Direction
>>> led = DigitalInOut(any_gpio)
>>> led.direction = Direction.OUTPUT

PyPortal (alpha.3):

>>> led.value = True
>>> led.value
True

(the LED is ON)

vs.

Saola (alpha.3):

>>> led.value = True
>>> led.value
False

(the LED is ON)

[edited to explicitly show pin is set up in either case as an output]

@jepler
Copy link
jepler commented Aug 30, 2020

If it's not intended to be able to read back the value previously set on an output pin, accessing the value property to read it should give an exception.

I think the problem arises because the esp-idf defines the return value of this routine in a surprising way, rather than returning the value currently driven onto the pin:

 * @brief  GPIO get input level
 *
 * @warning If the pad is not configured for input (or input and output) the returned value is always 0.
 *
 * @param  hw Peripheral GPIO hardware instance address.
 * @param  gpio_num GPIO number. If you want to get the logic level of e.g. pin GPIO16, gpio_num should be GPIO_NUM_16 (16);
 *
 * @return
 *     - 0 the GPIO input level is 0
 *     - 1 the GPIO input level is 1

@anecdata
Copy link
Member Author
anecdata commented Aug 30, 2020

FWIW, input behaves the same on both. It's conceptually an easier case to make that it's an error since the value is controlled by an external source:

>>> pin = DigitalInOut(any_gpio)
>>> pin.direction = Direction.INPUT
>>> pin.value
False
>>> pin.value = True
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: Cannot set value when direction is input.

addendum...

analog outputs don't allow reading the value:

>>> import board
>>> from analogio import AnalogOut
>>> a = AnalogOut(board.A0)
>>> a.value
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: unreadable attribute

@dhalbert dhalbert added the espressif applies to multiple Espressif chips label Aug 31, 2020
@dhalbert dhalbert added this to the 6.x.x - Bug Fixes milestone Aug 31, 2020
tannewt added a commit that referenced this issue Oct 1, 2020
Also fix two bugs:
* Crash when resetting board.SPI when it hasn't been inited.
* Reading back the output value is always false. Fixes #3353
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug espressif applies to multiple Espressif chips good first issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants
0