RC522与stm32之间通过SPI通讯 STM32f103对rc522寄存器进行配置后读取磁卡ID
单片机源程序如下:
- #include "main.h"
- #include "pc_usart.h"
- #include "esp8266_usart.h"
- #include "spi.h"
- #include "rc522.h"
- #include "delay.h"
- #include "string.h"
- int main(void)
- {
- uint8_t Card_Type1[2];
- uint8_t Card_ID[4];
- uint8_t status;
- SystemInit();//系统时钟初始化
- PC_USART_Config();//串口1初始化
- delay_init();
- RC522_IO_Init();
- PcdReset();
- PcdAntennaOff();
- delay_ms(2);
- PcdAntennaOn();
-
- printf("Card Type");
-
- while(1)
- {
- delay_ms(10);
- printf("Card Type");
- if(MI_OK==PcdRequest(0x52, Card_Type1))
- {
- uint16_t cardType = (Card_Type1[0]<<8)|Card_Type1[1];
- printf("Card Type(0x%04X):",cardType);
- switch(cardType){
- case 0x4400:
- printf("Mifare UltraLight\n\r");
- break;
- case 0x0400:
- printf("Mifare One(S50)\n\r");
- break;
- case 0x0200:
- printf("Mifare One(S70)\n\r");
- break;
- case 0x0800:
- printf("Mifare Pro(X)\n\r");
- break;
- case 0x4403:
- printf("Mifare DESFire\n\r");
- break;
- default:
- printf("Unknown Card\n\r");
- continue;
- }
- //delay_ms(10);
- status = PcdAnticoll(Card_ID);//防冲撞
- if(status != MI_OK){
- printf("Anticoll Error\n\r");
- continue;
- }else{
- printf("Serial Number:%02X%02X%02X%02X\n\r",Card_ID[0],Card_ID[1],Card_ID[2],Card_ID[3]);
- }
- }
- }
- }
- /*********************************END OF FILE**********************************/
复制代码
所有资料51hei提供下载:
0.读卡.rar
(300.55 KB, 下载次数: 124)
|