当前位置:网站首页>Stm32+mfrc522 completes IC card number reading, password modification, data reading and writing
Stm32+mfrc522 completes IC card number reading, password modification, data reading and writing
2022-07-26 09:11:00 【InfoQ】
One 、 Introduction to the environment
Two 、 Function is introduced
3、 ... and 、MFR522 Introduce

Four 、IC Card Introduction
M1 Card detailed indicators
- Chip type :PhilipsMifare1ICS50
- storage capacity :8Kbit,16 Zones , Two passwords per partition ;
- Working frequency :13.56?MHz;
- Communication rate :106KBoud;
- Reading and writing distance :2.5~10cm;
- Reading and writing time :1~2ms;
- working temperature :-20℃~55℃;
- Erasure life :>100,000 Time ;
- Save the data :>10 year ;
- Dimensions :ISO Standard card 85.6x54x0.82;
- Packaging materials :PVC、PET、PETG、0.13mm Copper wire ;


- The first 0 A sector is used to store the manufacturer code , Opinion fixed line , Non modifiable .
- Blocks per sector 0、 block 1、 block 2 For data blocks , Can be used to store data . Data blocks can be read and written .
- Blocks per sector 3 For the control block , Including the password A、 Storage control 、 password B. The specific structure is as follows :

- The password and control bits of each sector are independent , You can set your own password and access control according to your actual needs . Access control is 4 Bytes , common 32 position , Every block in a sector ( Including data and control blocks ) Access conditions are determined by password and access control , In access control, each block has a corresponding three control bits . The definition is as follows :






- Represents the permissions of the control block
Can read control bytes (4 individual ), Unable to write control byte
Can read and write B password

5、 ... and 、 Core code
5.1 rc522.c
#include "sys.h"
#include "RFID_RC522.h"
#include "delay.h"
#include "string.h"
#include "usart.h"
/*
The functionality : Porting interfaces --SPI Sequential read and write a byte
Function parameter :data: The data to be written
return return value : Data read
*/
u8 RC522_SPI_ReadWriteOneByte(u8 tx_data)
{
u8 rx_data=0;
u8 i;
for(i=0;i<8;i++)
{
RC522_SCLK=0;
if(tx_data&0x80){RC522_OUTPUT=1;}
else {RC522_OUTPUT=0;}
tx_data<<=1;
RC522_SCLK=1;
rx_data<<=1;
if(RC522_INPUT)rx_data|=0x01;
}
return rx_data;
}
/*
The functionality : initialization RC522 Of IO mouth
*/
void RC522_IO_Init(void)
{
RCC->APB2ENR|=1<<2; //PA Clock enable
RCC->APB2ENR|=1<<7; //PF Clock enable
//PA5 The clock RC522_SCLK
//PA6 Input RC522_INPUT
//PA7 Output RC522_OUTPUT
GPIOA->CRL&=0x000FFFFF;
GPIOA->CRL|=0x38300000;
GPIOA->ODR|=0x3<<5;
//RC522_RST <----->PF1-- Reset the foot
//RC522_SDA <----->PF0-- Film selection foot
GPIOF->CRL&=0xFFFFFF00;
GPIOF->CRL|=0x00000033;
GPIOF->ODR|=0x3<<0;
}
/*
Function description : Select the card and read the memory capacity of the card
Input parameters :serNum Incoming card serial number
return return value : Card capacity returned successfully
*/
u8 RC522_MFRC522_SelectTag(u8 *serNum) // Read card memory capacity
{
u8 i;
u8 status;
u8 size;
u8 recvBits;
u8 buffer[9];
buffer[0]=PICC_ANTICOLL1; // Anti collision code 1
buffer[1]=0x70;
buffer[6]=0x00;
for(i=0;i<4;i++)
{
buffer[i+2]=*(serNum+i); //buffer[2]-buffer[5] Is the card serial number
buffer[6]^=*(serNum+i); // Card check code
}
RC522_CalulateCRC(buffer,7,&buffer[7]); //buffer[7]-buffer[8] by RCR Check code
RC522_ClearBitMask(Status2Reg,0x08);
status=RC522_PcdComMF522(PCD_TRANSCEIVE,buffer,9,buffer,&recvBits);
if((status==MI_OK)&&(recvBits==0x18))
size=buffer[0];
else
size=0;
return size;
}
/*
The time delay function , Nanosecond
*/
void RC522_Delay(u32 ns)
{
u32 i;
for(i=0;i<ns;i++)
{
__nop();
__nop();
__nop();
}
}
/*
The functionality :RC522 Chip initialization
*/
void RC522_Init(void)
{
RC522_IO_Init(); //RC522 initialization
RC522_PcdReset(); // Reset RC522
RC522_PcdAntennaOff(); // Turn off the antenna
DelayMs(2); // Time delay 2 millisecond
RC522_PcdAntennaOn(); // Turn on the antenna
M500PcdConfigISOType('A'); // Set up RC632 How it works
}
/*
The functionality : Reset RC522
*/
void RC522_Reset(void)
{
RC522_PcdReset(); // Reset RC522
RC522_PcdAntennaOff(); // Turn off the antenna
DelayMs(2); // Time delay 2 millisecond
RC522_PcdAntennaOn(); // Turn on the antenna
}
/*
work can : Card search
Parameter description : req_code[IN]: Card search method
0x52 = All in the sensing area are consistent with 14443A Standard card
0x26 = Find a card that has not entered sleep state
pTagType[OUT]: Card type code
0x4400 = Mifare_UltraLight
0x0400 = Mifare_One(S50)
0x0200 = Mifare_One(S70)
0x0800 = Mifare_Pro(X)
0x4403 = Mifare_DESFire
return return value : Successfully returns MI_OK
*/
char RC522_PcdRequest(u8 req_code,u8 *pTagType)
{
char status;
u8 unLen;
u8 ucComMF522Buf[MAXRLEN]; // MAXRLEN 18
RC522_ClearBitMask(Status2Reg,0x08); // clear RC522 Register bit ,/ Receive data command
RC522_WriteRawRC(BitFramingReg,0x07); // Write RC632 register
RC522_SetBitMask(TxControlReg,0x03); // Set up RC522 Register bit
ucComMF522Buf[0]=req_code; // Card search method
status=RC522_PcdComMF522(PCD_TRANSCEIVE,ucComMF522Buf,1,ucComMF522Buf,&unLen); // adopt RC522 and ISO14443 Card communication
if((status==MI_OK)&&(unLen==0x10))
{
*pTagType=ucComMF522Buf[0];
*(pTagType+1)=ucComMF522Buf[1];
}
else
{
status = MI_ERR;
}
return status;
}
/*
work can : Collision proof
Parameter description : pSnr[OUT]: Card serial number ,4 byte
return return : Successfully returns MI_OK
*/
char RC522_PcdAnticoll(u8 *pSnr)
{
char status;
u8 i,snr_check=0;
u8 unLen;
u8 ucComMF522Buf[MAXRLEN];
RC522_ClearBitMask(Status2Reg,0x08); // clear RC522 Register bit
RC522_WriteRawRC(BitFramingReg,0x00); // Write
RC522_ClearBitMask(CollReg,0x80); // clear
ucComMF522Buf[0]=PICC_ANTICOLL1; //PICC_ANTICOLL1 = 0x93
ucComMF522Buf[1]=0x20;
status=RC522_PcdComMF522(PCD_TRANSCEIVE,ucComMF522Buf,2,ucComMF522Buf,&unLen); //0x0c, adopt RC522 and ISO14443 Card communication
//PCD_TRANSCEIVE = Send and receive data
//2: The length of data bytes written to the card
//ucComMF522Buf: The address where the data is stored
//unLen: The length of data read from the card
if(status==MI_OK)
{
for(i=0;i<4;i++)
{
*(pSnr+i)=ucComMF522Buf[i]; // Assign the read card number to pSnr
snr_check^=ucComMF522Buf[i];
}
if(snr_check!=ucComMF522Buf[i])
{
status = MI_ERR;
}
}
RC522_SetBitMask(CollReg,0x80);
return status;
}
/*
work can : Select card
Parameter description :pSnr[IN]: Card serial number ,4 byte
return return : Successfully returns MI_OK
*/
char RC522_PcdSelect(u8 *pSnr)
{
char status;
u8 i;
u8 unLen;
u8 ucComMF522Buf[MAXRLEN];
ucComMF522Buf[0]=PICC_ANTICOLL1;
ucComMF522Buf[1]=0x70;
ucComMF522Buf[6]=0;
for(i=0;i<4;i++)
{
ucComMF522Buf[i+2]=*(pSnr+i);
ucComMF522Buf[6]^=*(pSnr+i);
}
RC522_CalulateCRC(ucComMF522Buf,7,&ucComMF522Buf[7]); // use MF522 Calculation CRC16 function , Check the data
RC522_ClearBitMask(Status2Reg,0x08); // clear RC522 Register bit
status=RC522_PcdComMF522(PCD_TRANSCEIVE,ucComMF522Buf,9,ucComMF522Buf,&unLen);
if((status==MI_OK)&&(unLen==0x18))status=MI_OK;
else status=MI_ERR;
return status;
}
/*
work can : Verify the card password
Parameter description :auth_mode[IN]: Password authentication mode
0x60 = verification A secret key
0x61 = verification B secret key
addr[IN]: Block address
pKey[IN]: Sector password
pSnr[IN]: Card serial number ,4 byte
return return : Successfully returns MI_OK
*/
char RC522_PcdAuthState(u8 auth_mode,u8 addr,u8 *pKey,u8 *pSnr)
{
char status;
u8 unLen;
u8 ucComMF522Buf[MAXRLEN]; //MAXRLEN 18( Size of array )
// Verification mode + Block address + Sector password + Card serial number
ucComMF522Buf[0]=auth_mode;
ucComMF522Buf[1]=addr;
memcpy(&ucComMF522Buf[2],pKey,6); // Copy , Copy
memcpy(&ucComMF522Buf[8],pSnr,4);
status=RC522_PcdComMF522(PCD_AUTHENT,ucComMF522Buf,12,ucComMF522Buf,&unLen);
if((status!= MI_OK)||(!(RC522_ReadRawRC(Status2Reg)&0x08)))status = MI_ERR;
return status;
}
/*
work can : Read M1 A data card
Parameter description :
addr: Block address
p : Read out block data ,16 byte
return return : Successfully returns MI_OK
*/
char RC522_PcdRead(u8 addr,u8 *p)
{
char status;
u8 unLen;
u8 i,ucComMF522Buf[MAXRLEN]; //18
ucComMF522Buf[0]=PICC_READ;
ucComMF522Buf[1]=addr;
RC522_CalulateCRC(ucComMF522Buf,2,&ucComMF522Buf[2]);
status=RC522_PcdComMF522(PCD_TRANSCEIVE,ucComMF522Buf,4,ucComMF522Buf,&unLen);// adopt RC522 and ISO14443 Card communication
if((status==MI_OK&&(unLen==0x90)))
{
for(i=0;i<16;i++)
{
*(p +i)=ucComMF522Buf[i];
}
}
else
{
status=MI_ERR;
}
return status;
}
/*
work can : Write data to the M1 Card designation block
Parameter description :addr: Block address
p : Data written to the block ,16 byte
return return : Successfully returns MI_OK
*/
char RC522_PcdWrite(u8 addr,u8 *p)
{
char status;
u8 unLen;
u8 i,ucComMF522Buf[MAXRLEN];
ucComMF522Buf[0]=PICC_WRITE;// 0xA0 // Write a piece
ucComMF522Buf[1]=addr; // Block address
RC522_CalulateCRC(ucComMF522Buf,2,&ucComMF522Buf[2]);
status=RC522_PcdComMF522(PCD_TRANSCEIVE,ucComMF522Buf,4,ucComMF522Buf,&unLen);
if((status!= MI_OK)||(unLen != 4)||((ucComMF522Buf[0]&0x0F)!=0x0A))
{
status = MI_ERR;
}
if(status==MI_OK)
{
for(i=0;i<16;i++)// towards FIFO Write 16Byte data
{
ucComMF522Buf[i]=*(p +i);
}
RC522_CalulateCRC(ucComMF522Buf,16,&ucComMF522Buf[16]);
status = RC522_PcdComMF522(PCD_TRANSCEIVE,ucComMF522Buf,18,ucComMF522Buf,&unLen);
if((status != MI_OK)||(unLen != 4)||((ucComMF522Buf[0]&0x0F)!=0x0A))
{
status = MI_ERR;
}
}
return status;
}
/*
work can : Command the card to sleep
return return : Successfully returns MI_OK
*/
char RC522_PcdHalt(void)
{
u8 status;
u8 unLen;
u8 ucComMF522Buf[MAXRLEN]; //MAXRLEN==18
status=status;
ucComMF522Buf[0]=PICC_HALT;
ucComMF522Buf[1]=0;
RC522_CalulateCRC(ucComMF522Buf,2,&ucComMF522Buf[2]);
status=RC522_PcdComMF522(PCD_TRANSCEIVE,ucComMF522Buf,4,ucComMF522Buf,&unLen);
return MI_OK;
}
/*
work can : use MF522 Calculation CRC16 function
ginseng Count :
*pIn : To read CRC The data of
len:- Data length
*pOut: Calculated CRC result
*/
void RC522_CalulateCRC(u8 *pIn ,u8 len,u8 *pOut )
{
u8 i,n;
RC522_ClearBitMask(DivIrqReg,0x04); //CRCIrq = 0
RC522_WriteRawRC(CommandReg,PCD_IDLE);
RC522_SetBitMask(FIFOLevelReg,0x80); // clear FIFO The pointer
// towards FIFO Middle write data
for(i=0;i<len;i++)
{
RC522_WriteRawRC(FIFODataReg,*(pIn +i)); // Start RCR Calculation
}
RC522_WriteRawRC(CommandReg,PCD_CALCCRC); // wait for CRC The calculation is complete
i=0xFF;
do
{
n=RC522_ReadRawRC(DivIrqReg);
i--;
}
while((i!=0)&&!(n&0x04));//CRCIrq = 1
// Read CRC The result of the calculation is
pOut[0]=RC522_ReadRawRC(CRCResultRegL);
pOut[1]=RC522_ReadRawRC(CRCResultRegM);
}
/*
work can : Reset RC522
return return : Successfully returns MI_OK
*/
char RC522_PcdReset(void)
{
RC522_RST=1; //PF1 Write 1
RC522_Delay(10);
RC522_RST=0; //PF1 clear 0
RC522_Delay(10);
RC522_RST=1; //PF1 Write 1
RC522_Delay(10);
RC522_WriteRawRC(CommandReg,PCD_RESETPHASE); // Write RC632 register , Reset
RC522_WriteRawRC(CommandReg,PCD_RESETPHASE); // Write RC632 register , Reset
RC522_Delay(10);
RC522_WriteRawRC(ModeReg,0x3D); // and Mifare Card communication ,CRC Initial value 0x6363
RC522_WriteRawRC(TReloadRegL,30); // Write RC632 register
RC522_WriteRawRC(TReloadRegH,0);
RC522_WriteRawRC(TModeReg,0x8D);
RC522_WriteRawRC(TPrescalerReg,0x3E);
RC522_WriteRawRC(TxAutoReg,0x40);// It has to be
return MI_OK;
}
/*
The functionality : Set up RC632 How it works
*/
char M500PcdConfigISOType(u8 type)
{
if(type=='A') //ISO14443_A
{
RC522_ClearBitMask(Status2Reg,0x08); // clear RC522 Register bit
RC522_WriteRawRC(ModeReg,0x3D); //3F//CRC Initial value 0x6363
RC522_WriteRawRC(RxSelReg,0x86); //84
RC522_WriteRawRC(RFCfgReg,0x7F); //4F // Adjust the sensing distance of the card //RxGain = 48dB Adjust the card sensing distance
RC522_WriteRawRC(TReloadRegL,30); //tmoLength);// TReloadVal = 'h6a =tmoLength(dec)
RC522_WriteRawRC(TReloadRegH,0);
RC522_WriteRawRC(TModeReg,0x8D);
RC522_WriteRawRC(TPrescalerReg,0x3E);
RC522_Delay(1000);
RC522_PcdAntennaOn(); // Turn on the antenna
}
else return 1; // Failure , return 1
return MI_OK; // Successfully returns 0
}
/*
work can : read RC632 register
Parameter description :Address[IN]: Register address
return return : Read out value
*/
u8 RC522_ReadRawRC(u8 Address)
{
u8 ucAddr;
u8 ucResult=0;
RC522_CS=0; // Film selection RC522
ucAddr=((Address<<1)&0x7E)|0x80;
RC522_SPI_ReadWriteOneByte(ucAddr); // dispatch orders
ucResult=RC522_SPI_ReadWriteOneByte(0); // Read RC522 Returned data
RC522_CS=1; // Release the selection line (PF0)
return ucResult; // Returns the data read
}
/*
work can : Write RC632 register
Parameter description :Address[IN]: Register address
value[IN] : Value written
*/
void RC522_WriteRawRC(u8 Address,u8 value)
{
u8 ucAddr;
RC522_CS=0; //PF0 Write 0 (SDA)(SPI1 Film selection line , Low level active )
ucAddr=((Address<<1)&0x7E);
RC522_SPI_ReadWriteOneByte(ucAddr); //SPI1 Send a byte
RC522_SPI_ReadWriteOneByte(value); //SPI1 Send a byte
RC522_CS=1; //PF1 Write 1(SDA)(SPI1 Film selection line )
}
/*
work can : Set up RC522 Register bit
Parameter description :reg[IN]: Register address
mask[IN]: Set value
*/
void RC522_SetBitMask(u8 reg,u8 mask)
{
char tmp=0x0;
tmp=RC522_ReadRawRC(reg); // read RC632 register
RC522_WriteRawRC(reg,tmp|mask); // Write RC632 register
}
/*
work can : clear RC522 Register bit
Parameter description :reg[IN]: Register address
mask[IN]: Clearance value
*/
void RC522_ClearBitMask(u8 reg,u8 mask)
{
char tmp=0x0;
tmp=RC522_ReadRawRC(reg); // read RC632 register
RC522_WriteRawRC(reg,tmp&~mask); // clear bit mask
}
/*
work can : adopt RC522 and ISO14443 Card communication
Parameter description :Command[IN]:RC522 Command word
pIn [IN]: adopt RC522 Data sent to the card
InLenByte[IN]: The byte length of the transmitted data
pOut [OUT]: The received card returns data
*pOutLenBit[OUT]: Returns the bit length of the data
*/
char RC522_PcdComMF522(u8 Command,u8 *pIn,u8 InLenByte,u8 *pOut,u8 *pOutLenBit)
{
char status=MI_ERR;
u8 irqEn=0x00;
u8 waitFor=0x00;
u8 lastBits;
u8 n;
u16 i;
switch(Command)
{
case PCD_AUTHENT: // Verify key
irqEn=0x12;
waitFor=0x10;
break;
case PCD_TRANSCEIVE: // Send and receive data
irqEn=0x77;
waitFor=0x30;
break;
default:
break;
}
RC522_WriteRawRC(ComIEnReg,irqEn|0x80);
RC522_ClearBitMask(ComIrqReg,0x80); // Clear all middle breaks
RC522_WriteRawRC(CommandReg,PCD_IDLE);
RC522_SetBitMask(FIFOLevelReg,0x80); // clear FIFO cache
for(i=0;i<InLenByte;i++)
{
RC522_WriteRawRC(FIFODataReg,pIn[i]);
}
RC522_WriteRawRC(CommandReg,Command);
if(Command==PCD_TRANSCEIVE)
{
RC522_SetBitMask(BitFramingReg,0x80); // Start transmission
}
// There is a problem , The following loop
//i = 600;// Adjust according to the clock frequency , operation M1 Maximum waiting time for card 25ms
i=2000;
do
{
n=RC522_ReadRawRC(ComIrqReg);
i--;
}
while((i!=0)&&!(n&0x01)&&!(n&waitFor));
RC522_ClearBitMask(BitFramingReg,0x80);
if(i!=0)
{
if(!(RC522_ReadRawRC(ErrorReg)&0x1B))
{
status=MI_OK;
if(n&irqEn&0x01)
{
status=MI_NOTAGERR;
}
if(Command==PCD_TRANSCEIVE)
{
n=RC522_ReadRawRC(FIFOLevelReg);
lastBits=RC522_ReadRawRC(ControlReg)&0x07;
if(lastBits)
{
*pOutLenBit=(n-1)*8+lastBits;
}
else
{
*pOutLenBit=n*8;
}
if(n==0)n=1;
if(n>MAXRLEN)n=MAXRLEN;
for(i=0; i<n; i++)
{
pOut[i]=RC522_ReadRawRC(FIFODataReg);
}
}
}
else
{
status=MI_ERR;
}
}
RC522_SetBitMask(ControlReg,0x80);// stop timer now
RC522_WriteRawRC(CommandReg,PCD_IDLE);
return status;
}
/*
The functionality : Turn on the antenna
ginseng Count : There should be at least... Between each start-up or shutdown of natural danger launch 1ms The interval of
*/
void RC522_PcdAntennaOn(void)
{
u8 i;
i=RC522_ReadRawRC(TxControlReg);
if(!(i&0x03))
{
RC522_SetBitMask(TxControlReg,0x03);
}
}
/*
The functionality : Turn off the antenna
ginseng Count : There should be at least... Between each start-up or shutdown of natural danger launch 1ms The interval of
*/
void RC522_PcdAntennaOff(void)
{
RC522_ClearBitMask(TxControlReg,0x03); // clear RC522 Register bit
}
5.2 rc522.h
#ifndef RFID_RC522_H
#define RFID_RC522_H
#include "sys.h"
/*
RC522 External interface of RF module :
*1--SDA <----->PF0-- Film selection foot
*2--SCK <----->PA5-- Clock line
*3--MOSI<----->PA7-- Output
*4--MISO<----->PA6-- Input
*5-- In the air
*6--GND <----->GND
*7--RST <----->PF1-- Reset the foot
*8--VCC <----->VCC
*/
#define RC522_OUTPUT PAout(7)
#define RC522_INPUT PAin(6)
#define RC522_SCLK PAout(5)
#define RC522_CS PFout(0)
#define RC522_RST PFout(1)
//MF522 Command word
#define PCD_IDLE 0x00 // Cancel the current command
#define PCD_AUTHENT 0x0E // Verify key
#define PCD_RECEIVE 0x08 // receive data
#define PCD_TRANSMIT 0x04 // send data
#define PCD_TRANSCEIVE 0x0C // Send and receive data
#define PCD_RESETPHASE 0x0F // Reset
#define PCD_CALCCRC 0x03 //CRC Calculation
//Mifare_One Card command word
#define PICC_REQIDL 0x26 // The antenna searching area is not in sleep state , Returns the type of card
#define PICC_REQALL 0x52 // All cards in the antenna searching area , Returns the type of card
#define PICC_ANTICOLL1 0x93 // Collision proof
#define PICC_ANTICOLL2 0x95 // Collision proof
#define PICC_AUTHENT1A 0x60 // verification A secret key
#define PICC_AUTHENT1B 0x61 // verification B secret key Command authentication code
#define PICC_READ 0x30 // Reading block
#define PICC_WRITE 0xA0 // Write a piece
#define PICC_DECREMENT 0xC0 // Deduction
#define PICC_INCREMENT 0xC1 // Recharge
#define PICC_RESTORE 0xC2 // Block data to buffer
#define PICC_TRANSFER 0xB0 // Save data in buffer
#define PICC_HALT 0x50 // Sleep
//MF522 FIFO Length definition
#define DEF_FIFO_LENGTH 64 //FIFO size=64byte
#define MAXRLEN 18
//MF522 Register definition
// PAGE 0
#define RFU00 0x00
#define CommandReg 0x01
#define ComIEnReg 0x02
#define DivlEnReg 0x03
#define ComIrqReg 0x04
#define DivIrqReg 0x05
#define ErrorReg 0x06
#define Status1Reg 0x07
#define Status2Reg 0x08
#define FIFODataReg 0x09
#define FIFOLevelReg 0x0A
#define WaterLevelReg 0x0B
#define ControlReg 0x0C
#define BitFramingReg 0x0D
#define CollReg 0x0E
#define RFU0F 0x0F
// PAGE 1
#define RFU10 0x10
#define ModeReg 0x11
#define TxModeReg 0x12
#define RxModeReg 0x13
#define TxControlReg 0x14
#define TxAutoReg 0x15
#define TxSelReg 0x16
#define RxSelReg 0x17
#define RxThresholdReg 0x18
#define DemodReg 0x19
#define RFU1A 0x1A
#define RFU1B 0x1B
#define MifareReg 0x1C
#define RFU1D 0x1D
#define RFU1E 0x1E
#define SerialSpeedReg 0x1F
// PAGE 2
#define RFU20 0x20
#define CRCResultRegM 0x21
#define CRCResultRegL 0x22
#define RFU23 0x23
#define ModWidthReg 0x24
#define RFU25 0x25
#define RFCfgReg 0x26
#define GsNReg 0x27
#define CWGsCfgReg 0x28
#define ModGsCfgReg 0x29
#define TModeReg 0x2A
#define TPrescalerReg 0x2B
#define TReloadRegH 0x2C
#define TReloadRegL 0x2D
#define TCounterValueRegH 0x2E
#define TCounterValueRegL 0x2F
// PAGE 3
#define RFU30 0x30
#define TestSel1Reg 0x31
#define TestSel2Reg 0x32
#define TestPinEnReg 0x33
#define TestPinValueReg 0x34
#define TestBusReg 0x35
#define AutoTestReg 0x36
#define VersionReg 0x37
#define AnalogTestReg 0x38
#define TestDAC1Reg 0x39
#define TestDAC2Reg 0x3A
#define TestADCReg 0x3B
#define RFU3C 0x3C
#define RFU3D 0x3D
#define RFU3E 0x3E
#define RFU3F 0x3F
// and MF522 Error code returned during communication
#define MI_OK 0
#define MI_NOTAGERR 1
#define MI_ERR 2
#define SHAQU1 0X01
#define KUAI4 0X04
#define KUAI7 0X07
#define REGCARD 0xa1
#define CONSUME 0xa2
#define READCARD 0xa3
#define ADDMONEY 0xa4
/*
RC522 Various driving functions
*/
u8 RC522_SPI_ReadWriteOneByte(u8 tx_data);
void RC522_IO_Init(void);
u8 RC522_MFRC522_SelectTag(u8 *serNum);
void RC522_Delay(u32 ns);
void RC522_Init(void);
void RC522_Reset(void);
char RC522_PcdRequest(u8 req_code,u8 *pTagType);
char RC522_PcdAnticoll(u8 *pSnr);
char RC522_PcdSelect(u8 *pSnr);
char RC522_PcdAuthState(u8 auth_mode,u8 addr,u8 *pKey,u8 *pSnr);
char RC522_PcdRead(u8 addr,u8 *p);
char RC522_PcdWrite(u8 addr,u8 *p);
char RC522_PcdHalt(void);
void RC522_CalulateCRC(u8 *pIn ,u8 len,u8 *pOut );
char RC522_PcdReset(void);
char M500PcdConfigISOType(u8 type);
char M500PcdConfigISOType(u8 type);
u8 RC522_ReadRawRC(u8 Address);
void RC522_WriteRawRC(u8 Address,u8 value);
void RC522_SetBitMask(u8 reg,u8 mask) ;
void RC522_ClearBitMask(u8 reg,u8 mask);
char RC522_PcdComMF522(u8 Command,u8 *pIn,u8 InLenByte,u8 *pOut,u8 *pOutLenBit);
void RC522_PcdAntennaOn(void);
void RC522_PcdAntennaOff(void);
#endif
边栏推荐
- 力扣题DFS
- JS closure: binding of functions to their lexical environment
- Study notes of automatic control principle -- correction and synthesis of automatic control system
- “No input file specified “问题的处理
- ES6 modular import and export) (realize page nesting)
- Pytoch realizes logistic regression
- PHP和MySQL获取week值不一致的处理
- 谷粒学院的全部学习源码
- at、crontab
- The child and binary tree- open root inversion of polynomials
猜你喜欢
day06 作业--增删改查
TCP solves the problem of short write
服务器内存故障预测居然可以这样做!
NFT与数字藏品到底有何区别?
【LeetCode数据库1050】合作过至少三次的演员和导演(简单题)
Database operation topic 1
Node-v download and application, ES6 module import and export
Babbitt | metauniverse daily must read: does the future of metauniverse belong to large technology companies or to the decentralized Web3 world
redis原理和使用-安装和分布式配置
Day06 homework - skill question 7
随机推荐
839. 模拟堆
Day06 homework -- skill question 2
Overview of motion recognition evaluation
分布式跟踪系统选型与实践
[leetcode database 1050] actors and directors who have cooperated at least three times (simple question)
PHP page value transfer
垂直搜索
Learn more about the difference between B-tree and b+tree
Nuxt - 项目打包部署及上线到服务器流程(SSR 服务端渲染)
838. 堆排序
Rocky基础练习题-shell脚本2
Database operation topic 1
Two tips for pycharm to open multiple projects
The child and binary tree- open root inversion of polynomials
Unity topdown character movement control
JS - DataTables control on the number of displays per page
jvm命令归纳
Study notes of automatic control principle -- correction and synthesis of automatic control system
day06 作业--技能题1
Probability model in machine learning