Skip to content

Commit cdedaf1

Browse files
committed
Update I2C _wakeup to come out of power_down
`_wakeup` also puts the pn532 back into normal mode.
1 parent 790340e commit cdedaf1

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

adafruit_pn532/i2c.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
import adafruit_bus_device.i2c_device as i2c_device
4242
from digitalio import Direction
4343
from micropython import const
44-
from adafruit_pn532.adafruit_pn532 import PN532, BusyError, _reset
44+
from adafruit_pn532.adafruit_pn532 import PN532, BusyError
4545

4646
_I2C_ADDRESS = const(0x24)
4747

@@ -55,23 +55,23 @@ def __init__(self, i2c, *, irq=None, reset=None, req=None, debug=False):
5555
reset pin and debugging output.
5656
"""
5757
self.debug = debug
58-
self._irq = irq
5958
self._req = req
60-
if reset:
61-
_reset(reset)
6259
self._i2c = i2c_device.I2CDevice(i2c, _I2C_ADDRESS)
63-
super().__init__(debug=debug, reset=reset)
60+
super().__init__(debug=debug, irq=irq, reset=reset)
6461

6562
def _wakeup(self): # pylint: disable=no-self-use
6663
"""Send any special commands/data to wake up PN532"""
64+
if self._reset_pin:
65+
self._reset_pin.value = True
66+
time.sleep(0.01)
6767
if self._req:
6868
self._req.direction = Direction.OUTPUT
69-
self._req.value = True
70-
time.sleep(0.1)
7169
self._req.value = False
72-
time.sleep(0.1)
70+
time.sleep(0.01)
7371
self._req.value = True
74-
time.sleep(0.5)
72+
time.sleep(0.01)
73+
self.low_power = False
74+
self.SAM_configuration() # Put the PN532 back in normal mode
7575

7676
def _wait_ready(self, timeout=1):
7777
"""Poll PN532 if status byte is ready, up to `timeout` seconds"""
@@ -82,11 +82,10 @@ def _wait_ready(self, timeout=1):
8282
with self._i2c:
8383
self._i2c.readinto(status)
8484
except OSError:
85-
self._wakeup()
8685
continue
8786
if status == b"\x01":
8887
return True # No longer busy
89-
time.sleep(0.05) # lets ask again soon!
88+
time.sleep(0.01) # lets ask again soon!
9089
# Timed out!
9190
return False
9291

@@ -101,8 +100,6 @@ def _read_data(self, count):
101100
i2c.readinto(frame) # ok get the data, plus statusbyte
102101
if self.debug:
103102
print("Reading: ", [hex(i) for i in frame[1:]])
104-
else:
105-
time.sleep(0.1)
106103
return frame[1:] # don't return the status byte
107104

108105
def _write_data(self, framebytes):

0 commit comments

Comments
 (0)