Skip to content

Commit ec7ef71

Browse files
committed
add timeout to SPI readywait
1 parent 828db15 commit ec7ef71

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

adafruit_esp32spi/adafruit_esp32spi.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def _spi_select(self):
105105
self._cs.value = False # the actual select
106106
times = time.monotonic()
107107
while (time.monotonic() - times) < 1: # wait up to 1000ms
108-
if self._ready.value:
108+
if self._ready.value: # ok ready to send!
109109
return
110110
# some failure
111111
self._cs.value = True
@@ -119,10 +119,16 @@ def _spi_deselect(self):
119119
def wait_for_ready(self):
120120
if self._debug:
121121
print("Wait for ESP32 ready", end='')
122-
while self._ready.value == True:
122+
times = time.monotonic()
123+
while (time.monotonic() - times) < 10: # wait up to 10 seconds
124+
if self._ready.value == False: # we're ready!
125+
break
123126
if self._debug:
124127
print('.', end='')
125128
time.sleep(0.01)
129+
else:
130+
raise RuntimeError("ESP32 not responding")
131+
126132
if self._debug:
127133
print()
128134

0 commit comments

Comments
 (0)