Skip to content

Commit c165035

Browse files
committed
Fix blink example by correctly toggling output
The blink example was incorrect (as pointed out in issue #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.
1 parent 8fa7070 commit c165035

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

Diff for: examples/blink.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@
3030
#define RTC_IO_TOUCH_PAD2_REG (DR_REG_RTCIO_BASE + 0x9c)
3131
#define RTC_IO_TOUCH_PAD2_MUX_SEL_M (BIT(19))
3232
#define RTC_GPIO_OUT_REG (DR_REG_RTCIO_BASE + 0x0)
33-
#define RTC_GPIO_ENABLE_W1TS_REG (DR_REG_RTCIO_BASE + 0x10)
34-
#define RTC_GPIO_ENABLE_W1TC_REG (DR_REG_RTCIO_BASE + 0x14)
35-
#define RTC_GPIO_ENABLE_W1TS_S 14
36-
#define RTC_GPIO_ENABLE_W1TC_S 14
33+
#define RTC_GPIO_ENABLE_REG (DR_REG_RTCIO_BASE + 0xc)
34+
#define RTC_GPIO_ENABLE_S 14
3735
#define RTC_GPIO_OUT_DATA_S 14
3836
3937
# constants from:
@@ -62,8 +60,8 @@
6260
# connect GPIO to ULP (0: GPIO connected to digital GPIO module, 1: GPIO connected to analog RTC module)
6361
WRITE_RTC_REG(RTC_IO_TOUCH_PAD2_REG, RTC_IO_TOUCH_PAD2_MUX_SEL_M, 1, 1);
6462
65-
# GPIO shall be output, not input
66-
WRITE_RTC_REG(RTC_GPIO_OUT_REG, RTC_GPIO_OUT_DATA_S + gpio, 1, 1);
63+
# GPIO shall be output, not input (this also enables a pull-down by default)
64+
WRITE_RTC_REG(RTC_GPIO_ENABLE_REG, RTC_GPIO_ENABLE_S + gpio, 1, 1)
6765
6866
# store that we're done with initialisation
6967
move r0, magic
@@ -83,12 +81,12 @@
8381
8482
on:
8583
# turn on led (set GPIO)
86-
WRITE_RTC_REG(RTC_GPIO_ENABLE_W1TS_REG, RTC_GPIO_ENABLE_W1TS_S + gpio, 1, 1)
84+
WRITE_RTC_REG(RTC_GPIO_OUT_REG, RTC_GPIO_OUT_DATA_S + gpio, 1, 1)
8785
jump exit
8886
8987
off:
9088
# turn off led (clear GPIO)
91-
WRITE_RTC_REG(RTC_GPIO_ENABLE_W1TC_REG, RTC_GPIO_ENABLE_W1TC_S + gpio, 1, 1)
89+
WRITE_RTC_REG(RTC_GPIO_OUT_REG, RTC_GPIO_OUT_DATA_S + gpio, 1, 0)
9290
jump exit
9391
9492
exit:

0 commit comments

Comments
 (0)