1. 为什么要用Arduino
一提到,我们可能会想到ACR122、Proxmark3这些设备,还有Radiowar出售的专业级RFID设备,实际上我们完全可以自己使用arduino单片机和RC522这种RFID模组制作简易且足够使用的RFID读写器,并实现简单的攻防实验。为了实现这个目的,我们需要了解一些基本的RFID协议和射频收发器的基本参数知识
2. RC522芯片(读卡器)简介
MF RC522是应用于13.56MHz非接触式通信中高集成度的读写卡芯片,是NXP公司针对“三表”应用推出的一款低电压、低成本、体积小的非接触式读写 卡芯片,是智能仪表和便携式手持设备研发的较好选择。 MF RC522利用了先进的调制和解调概念,完全集成了在13.56MHz下所有类型的被动非接触式通信方式和协议。支持14443A兼容应答器信号。数字部 分处理ISO14443A帧和错误检测。此外,还支持快速CRYPTO1加密算法,用语验证MIFARE系列产品。MFRC522支持MIFARE系列更 高速的非接触式通信,双向数据传输速率高达424kbit/s。 作为13.56MHz高集成度读写卡系列芯片家族的新成员,MF RC522与MF RC500和MF RC530有不少相似之处,同时也具备许多特点和差异。它与主机间通信采用SPI模式,有利于减少连线,缩小PCB板体积,降低成本
NXP RC522微控制器是该单片机的核心
MF522-AN模块采用Philips MFRC522原装芯片设计读卡电路,使用方便,成本低廉,适用于设备开发、读卡器开发等高级应用的用户、需要进行射频卡终端设计/生产的用户。本模块可 直接装入各种读卡器模具。模块采用电压为3.3V,通过SPI接口简单的几条线就可以直接与用户任何CPU主板相连接通信,可以保证模块稳定可靠的工作、 读卡距离远
0x1: 电气参数简介
工作电流: 13—26mA/直流3.3V
空闲电流: 10-13mA/直流3.3V
休眠电流: <80uA
峰值电流: <30mA
工作频率: 13.56MHz
支持的卡类型
1. mifare1 S50
2. mifare1 S70
3. mifare UltraLight
4. mifare Pro
5. mifare Desfire
产品物理特性: 尺寸: 40mm×60mm
环境工作温度: 摄氏-20~80度
环境储存温度: 摄氏-40~85度
环境相对湿度: 相对湿度5%~95%
0x2: 模块原理图

0x3: MFRC522 Register SET
1. 通过地址总线,选通某个外设设备,这个过程通过向地址寄存器写入外设的内存基址完成
2. 选通数据总线
3. 向外设的"指令缓冲寄存器"中写入指令代码
4. 向外设的"指令参数寄存器"中写入指令参数。在RC522上通过一个FIFO存储器实现
5. 外设以轮询或者中断触发方式读取指令寄存器中的指令码,以及传入的参数,跳转到对应的"处理例程"
RC522的寄存器列表如下
//Page 0:Command and Status
Reserved00: Reserved for future use
CommandReg: Starts and stops commands execution
CommIEnReg: Controls bits to enable and disable the passing of interrupt Requests
DivlEnReg: Controls bits to enable and disable the passing of interrupt Requests
CommIrqReg: Contains interrupt Request bits
DivIrqReg: Contains interrupt Request bits
ErrorReg: Error bits showing the error status of the last command executed
Status1Reg: Contains status bits for communication
Status2Reg: Contains status bits of the receiver and transmitter
FIFODataReg: in and output of 64 byte FIFO buffer
FIFOLevelReg: indicates the number of bytes stored in the FIFO
WaterLevelReg: Defines the level for FIFO under and overflow warning
ControlReg: Contains miscellaneous Control Registers
BitFramingReg: Adjustments for bit oriented frames
CollReg: Bit position of the first bit collision detected on the RF-interface
Reserved01: Reserved for future use
//Page 1:Command
Reserved10: Reserved for future use
ModeReg: Defined general modes for transmitting and receiving
TxModeReg: Defines the transmission data rate and framing
RxModeReg: Defines the receive data rate and framing
TxControlReg: Control the logical behavior of the antenna driver pins TX1 and TX2
TxAutoReg
TxSelReg: Selects the internal sources for the antenna driver
RxSelReg: Selects internal receiver setttings
RxThresholdReg: Selects threadholds for the bit decoder
DemodReg: Defines demodulator settings
Reserved11: Reserved for future use
Reserved12: Reserved for future use
MifareReg
Reserved13: Reserved for future use
Reserved14: Reserved for future use
SerialSpeedReg: Selects the speed of the serial UART interface
//Page 2:CFG
Reserved20: Reserved for future use
CRCResultRegM: Shows the actual MSB values of the CRC calcalation
CRCResultRegL: Shows the actual LSB values of the CRC calcalation
Reserved21: Reserved for future use
ModWidthReg: Controls the settting of the ModWidth
Reserved22: Reserved for future use
RFCfgReg: Configures the receiver gain
GsNReg: Selects the conductance of the antenna driver pins TX1 and TX2 for modulation
CWGsPReg
ModGsPReg
TModeReg: Defines settings for the internal timer
TPrescalerReg
TReloadRegH: Describes the 16 bit timer reload value
TReloadRegL
TCounterValueRegH: Shows the 16 bit actual timer value
TCounterValueRegL
//Page 3:TestRegister
Reserved30: Reserved for future use
#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 Reserved31 0x3C
#define Reserved32 0x3D
#define Reserved33 0x3E
#define Reserved34 0x3F
0x4: MFRC522 Command Set
//MF522 command bits
#define PCD_IDLE 0x00 //NO action; cancel current commands
#define PCD_AUTHENT 0x0E //verify password key
#define PCD_RECEIVE 0x08 //receive data
#define PCD_TRANSMIT 0x04 //send data
#define