def sendrequest(): rc.ClearBitMask(0x04, 0x80) #CommIrqReg rc.Write_MFRC522( 0x02, 0xA2) #ComIEnReg, Enable err, timeout and receive interrupt buf = [] buf.append(0x26) rc.Write_MFRC522(0x0D, 0x07) # bout=rc.CalulateCRC(buf)#Calc CRC # buf.append(bout[0]) # buf.append(bout[1]) rc.Write_MFRC522(0xA0, 0x80) rc.Write_MFRC522(0x09, buf[0]) rc.Write_MFRC522(0x01, 0xC0) rc.Write_MFRC522(0x0D, 0x80) i = 0xff while True: n = rc.Read_MFRC522(0x04) i = i - 1 if (i == 0 or n & 0x30): if (i != 0): print "card detected!!" break rc.Write_MFRC522(0x01, 0x00) rc.ClearBitMask(0x0D, 0x80)
def sendrequest(): buf = [] buf.append(0x26) rc.Write_MFRC522(0x0D, 0x07) rc.Write_MFRC522(0x02, 00) #cancel current command execution rc.ClearBitMask(0x04, 0x80) #CommIrqReg rc.Write_MFRC522(0x02, 0xF7) #enable rc.Write_MFRC522(0xA0, 0x80) rc.Write_MFRC522(0x09, buf[0]) rc.Write_MFRC522(0x01, 0x0C) rc.SetBitMask(0x0D, 0x80) i = 0xff while True: n = rc.Read_MFRC522(0x04) i = i - 1 if (i == 0 or n & 0x20): break if (i != 0): #and (Read_MFRC522(0x06) & 0x1B)==0x00 print "card detected!!" rc.Write_MFRC522(0x01, 0x00) #or: rc.ClearBitMask(0x0D, 0x80)
import spi import signal import time rc.MFRC522_Init('/dev/spidev0.0', 1000000) #rc.Write_MFRC522(0x01, 0x10)# Power down mode: if ther is no SoftReset ##spi.openSPI('/dev/spidev0.0', 1000000) ##GPIO.setwarnings(False) GPIO.setmode(GPIO.BOARD) GPIO.setup(7, GPIO.IN) GPIO.setup(8, GPIO.OUT) GPIO.output(8, 0) #NRSTPD print "Welcome to the MFRC522 self test example" rc.Write_MFRC522(0x2A, 0x14) #TModeReg :2^10 + autorestart # was 0x14 rc.Write_MFRC522(0x2B, 0x00) #TPrescalerReg rc.Write_MFRC522(0x2C, 0xFF) #reload value: 65535 rc.Write_MFRC522(0x2D, 0xFe) rc.Write_MFRC522(0x0C, 0x40) #ControlReg: timer starts immediately #=> wait 4.8329 sec rc.Write_MFRC522( 0x11, 0x20) #transmitter can only be started if an RF field is generated def sendrequest(): buf = [] buf.append(0x26) rc.Write_MFRC522(0x0D, 0x07)
import RPi.GPIO as GPIO import rc522Lib as rc import signal import time continue_reading = True write="Marwen" rc.MFRC522_Init('/dev/spidev0.0', 1000000) print "Welcome to the MFRC522 data write example" i=0 while i<25: rc.Write_MFRC522(0x09, 0) i=i+1 rc.Write_MFRC522(0x01, 0x01) #rc.Write_MFRC522(0x0A, 0x80) ##initiate the FIFOLevelReg pointer rc.Write_MFRC522(0x36, 0x09) rc.Write_MFRC522(0x0A, 0x80) ##initiate the FIFOLevelReg pointer if rc.Read_MFRC522(0x05)==0x04: print "crc finished " rc.ClearBitMask(0x05, 0x04) #DivIrqReg rc.Write_MFRC522(0x09, 0x00) #rc.Write_MFRC522(0x03, 0x04) rc.Write_MFRC522(0x01, 0x03) #enable CRC Command i=0xff while i<0: n=Read_MFRC522(0x05)
continue_reading = True # Capture SIGINT for cleanup when the script is aborted def end_read(signal,frame): global continue_reading print "Ctrl+C captured, ending read." continue_reading = False signal.signal(signal.SIGINT, end_read) # Hook the SIGINT rc.MFRC522_Init('/dev/spidev0.0', 1000000) print "Welcome to the MFRC522 data read example" print "Press Ctrl-C to stop." # This loop keeps checking for chips. If one is near it will get the UID and authenticate print rc.Read_MFRC522(0x01) #==0x0F :reset rc.Write_MFRC522(0x01, 0x10) #rc.Write_MFRC522(0x11,0x20) while continue_reading: # Scan for cards (status,TagType) = rc.MFRC522_Request(0x26) #PICC_REQIDL # If a card is found if status == 0: #MI_OK print "Card detected" # Get the UID of the card (status,uid) = rc.MFRC522_Anticoll() #print("(uid, status): ",uid,"\t ", status) # If we have the UID, continue if status == 0: print "Card read UID: %s,%s,%s,%s" % (uid[0], uid[1], uid[2], uid[3]) # This is the default key for authentication key = [0xA0,0xA1,0xA2,0xA3,0xA4,0xA5]