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)
Exemplo n.º 3
0
import signal
import time

continue_reading = True
write = "Hello World!"
# Fill the data with 0xFF
data = []
for l in write:
    data.append(ord(l))
for x in range(len(write), 16):
    data.append(0xF0)

rc.MFRC522_Init('/dev/spidev0.0', 1000000)
print "Welcome to the MFRC522 data write example"

print rc.Read_MFRC522(0x01)  #==0x0F :reset

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: ",uid)
    # 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]
Exemplo n.º 4
0
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)
    i=i-1
    if(i==0 or n&0x04):
        break
print "crc MSB: ",rc.Read_MFRC522(0x21) #CRCResultRegM
print "crc LSB: ",rc.Read_MFRC522(0x22)
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(0x04, 0x81) #ComIrqReg
##rc.Write_MFRC522(0x02, 0x04) #ComIEnReg: Activate interrupt signal pin IRQ
rc.Write_MFRC522(0x0C, 0x40)  #ControlReg: timer starts immediately
#=> wait 4.8329 sec
#rc.Write_MFRC522(0x01, 0x01)#*_* stores 25 bytes from the FIFO to the internal buffer
rc.Write_MFRC522(
    0x11, 0x20)  #transmitter can only be started if an RF field is generated
print "{0:x}".format(rc.Read_MFRC522(0x14))
rc.Write_MFRC522(0x14, 0x83)
rc.Write_MFRC522(0x02, 00)


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)