-
Notifications
You must be signed in to change notification settings - Fork 25
Questiona about GPIO Output (LED) example #78
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
You are very correct. That code is indeed incorrect. Some bad copy-pasting that happened to work(ish). The correct way would be to set the port to output enabled once with this instruction:
and then to toggle the LED on and off with these instructions:
Alternatively one can use the I just tested this with a power profiler (nordic PPK2), which supports reading in logic signals alongside the power profile. When I connect my GPIO output to the logic port with the current (wrong) When I instead fix the code as per above, I correctly see the highs and lows of the GPIO output from via the logic port. Thanks for picking this up. I will create a PR for this soon. |
Great, thanks explaining - I thought that was what was going on, but I'm using these examples to learn how to make a virtual SPI port in the ULP and I'm not quite used to the GPIO/RTC muxes in this thing yet. |
The blink example was incorrect (as pointed out in issue micropython#78). The example was toggling the GPIOs "output enable" state, instead of keeping "output enable" on and then toggling the output value of the pin. It "accidentally" worked, because we initally set the output value to 1 (high) and thus, whenever "output enable" was set, the LED lit up, and when "output enable" was turned off, the pin was left floating without any output voltage and the LED therefore turned off. The new approach correctly enables "output enable" at the start, and then only toggles the output value of the pin on and off. This change was also tested with a logic analyser, showing that before this change, the logic analyser could not correcly detect a LOW state after a HIGH state, because the pin was floating without a pull-down resistor in place, whenever it was not in "output enable" mode. After this change, the logic analyser correctly detected all LOW and HIGH states, because the pin remained in "output enable" mode (and the ESP32 has a pull-down configured by default) and only the output value was toggled.
@wz2b I have now merged the fix. Thanks again for reporting it. |
micropython-esp32-ulp/examples/blink.py
Line 86 in 8fa7070
Do I understand in this bit of code that you're turning the led on and off by enabling or disabling the GPIO output? I'm curious why you would have done that, rather than always initializing the pin as an output, then writing to RTCIO_RTC_GPIO_OUT_REG, RTCIO_RTC_GPIO_OUT_W1TS_REG, or RTCIO_RTC_GPIO_OUT_W1TC_REG?
The text was updated successfully, but these errors were encountered: