diff --git a/adafruit_pn532/i2c.py b/adafruit_pn532/i2c.py index 2d9baca..9c3ee09 100644 --- a/adafruit_pn532/i2c.py +++ b/adafruit_pn532/i2c.py @@ -41,7 +41,7 @@ import time import adafruit_bus_device.i2c_device as i2c_device from digitalio import Direction from micropython import const -from adafruit_pn532.adafruit_pn532 import PN532, BusyError, _reset +from adafruit_pn532.adafruit_pn532 import PN532, BusyError _I2C_ADDRESS = const(0x24) @@ -55,23 +55,23 @@ class PN532_I2C(PN532): reset pin and debugging output. """ self.debug = debug - self._irq = irq self._req = req - if reset: - _reset(reset) self._i2c = i2c_device.I2CDevice(i2c, _I2C_ADDRESS) - super().__init__(debug=debug, reset=reset) + super().__init__(debug=debug, irq=irq, reset=reset) def _wakeup(self): # pylint: disable=no-self-use """Send any special commands/data to wake up PN532""" + if self._reset_pin: + self._reset_pin.value = True + time.sleep(0.01) if self._req: self._req.direction = Direction.OUTPUT - self._req.value = True - time.sleep(0.1) self._req.value = False - time.sleep(0.1) + time.sleep(0.01) self._req.value = True - time.sleep(0.5) + time.sleep(0.01) + self.low_power = False + self.SAM_configuration() # Put the PN532 back in normal mode def _wait_ready(self, timeout=1): """Poll PN532 if status byte is ready, up to `timeout` seconds""" @@ -82,11 +82,10 @@ class PN532_I2C(PN532): with self._i2c: self._i2c.readinto(status) except OSError: - self._wakeup() continue if status == b"\x01": return True # No longer busy - time.sleep(0.05) # lets ask again soon! + time.sleep(0.01) # lets ask again soon! # Timed out! return False @@ -101,8 +100,6 @@ class PN532_I2C(PN532): i2c.readinto(frame) # ok get the data, plus statusbyte if self.debug: print("Reading: ", [hex(i) for i in frame[1:]]) - else: - time.sleep(0.1) return frame[1:] # don't return the status byte def _write_data(self, framebytes):