Skip to content

Commit

Permalink
Fix issue 69: follow the new change of SPI-Py API
Browse files Browse the repository at this point in the history
Tehis patch update code to match Python3 version,
and fix the function api problem of new SPI-Py PKG in mxgxw#69
  • Loading branch information
kuihao committed Mar 12, 2022
1 parent 11839f1 commit 16b7756
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions MFRC522.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,10 @@ class MFRC522:
Reserved34 = 0x3F

serNum = []
device_0 = spi.openSPI(device="/dev/spidev0.0", mode=0, speed=1000000)

def __init__(self, dev='/dev/spidev0.0', spd=1000000):
spi.openSPI(device=dev,speed=spd)
spi.openSPI(device=dev,mode=0,speed=spd)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(self.NRSTPD, GPIO.OUT)
GPIO.output(self.NRSTPD, 1)
Expand All @@ -138,10 +139,12 @@ def MFRC522_Reset(self):
self.Write_MFRC522(self.CommandReg, self.PCD_RESETPHASE)

def Write_MFRC522(self, addr, val):
spi.transfer(((addr<<1)&0x7E,val))
#spi.transfer(((addr<<1)&0x7E,val)) # abandoned https://github.com/mxgxw/MFRC522-python/issues/69
spi.transfer(self.device_0, ((addr<<1)&0x7E,val))

def Read_MFRC522(self, addr):
val = spi.transfer((((addr<<1)&0x7E) | 0x80,0))
#val = spi.transfer((((addr<<1)&0x7E) | 0x80,0)) # abandoned https://github.com/mxgxw/MFRC522-python/issues/69
val = spi.transfer(self.device_0, (((addr<<1)&0x7E) | 0x80,0))
return val[1]

def SetBitMask(self, reg, mask):
Expand Down

0 comments on commit 16b7756

Please sign in to comment.