1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844
| #include "bsp_rc522.h" #include "board.h"
void RC522_Init(void){ RCC_APB2PeriphClockCmd(RCC_GPIO, ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_CS|GPIO_SCK|GPIO_MOSI|GPIO_RST; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(PORT_GPIO, &GPIO_InitStructure); GPIO_SetBits(PORT_GPIO, GPIO_CS|GPIO_SCK|GPIO_MOSI|GPIO_RST);
GPIO_InitStructure.GPIO_Pin = GPIO_MISO; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_Init(PORT_GPIO, &GPIO_InitStructure); }
void RC522_SPI_SendByte( uint8_t byte ){ uint8_t n; for( n=0;n<8;n++ ){ if( byte&0x80 ) RC522_MOSI_1(); else RC522_MOSI_0();
delay_us(200); RC522_SCK_0(); delay_us(200); RC522_SCK_1(); delay_us(200);
byte<<=1; } }
uint8_t RC522_SPI_ReadByte( void ){ uint8_t n,data; for( n=0;n<8;n++ ){ data<<=1; RC522_SCK_0(); delay_us(200);
if( RC522_MISO_GET()==1 ) data|=0x01;
delay_us(200); RC522_SCK_1(); delay_us(200);
} return data; }
uint8_t RC522_Read_Register( uint8_t Address ){ uint8_t data,Addr;
Addr = ( (Address<<1)&0x7E )|0x80;
RC522_CS_Enable(); RC522_SPI_SendByte( Addr ); data = RC522_SPI_ReadByte(); RC522_CS_Disable();
return data; }
void RC522_Write_Register( uint8_t Address, uint8_t data ){ uint8_t Addr;
Addr = ( Address<<1 )&0x7E;
RC522_CS_Enable(); RC522_SPI_SendByte( Addr ); RC522_SPI_SendByte( data ); RC522_CS_Disable(); }
void RC522_SetBit_Register( uint8_t Address, uint8_t mask ){ uint8_t temp; temp = RC522_Read_Register( Address ); RC522_Write_Register( Address, temp|mask ); }
void RC522_ClearBit_Register( uint8_t Address, uint8_t mask ){ uint8_t temp; temp = RC522_Read_Register( Address ); RC522_Write_Register( Address, temp&(~mask) ); }
void RC522_Antenna_On( void ){ uint8_t k; k = RC522_Read_Register( TxControlReg ); if( !( k&0x03 ) ) RC522_SetBit_Register( TxControlReg, 0x03 ); }
void RC522_Antenna_Off( void ){ RC522_ClearBit_Register( TxControlReg, 0x03 ); }
void RC522_Rese( void ){ RC522_Reset_Disable(); delay_us ( 1 ); RC522_Reset_Enable(); delay_us ( 1 ); RC522_Reset_Disable(); delay_us ( 1 ); RC522_Write_Register( CommandReg, 0x0F ); while( RC522_Read_Register( CommandReg )&0x10 ) ;
delay_us ( 1 ); RC522_Write_Register( ModeReg, 0x3D ); RC522_Write_Register( TReloadRegL, 30 ); RC522_Write_Register( TReloadRegH, 0 ); RC522_Write_Register( TModeReg, 0x8D ); RC522_Write_Register( TPrescalerReg, 0x3E ); RC522_Write_Register( TxAutoReg, 0x40 ); }
void RC522_Config_Type( char Type ){ if( Type=='A' ){ RC522_ClearBit_Register( Status2Reg, 0x08 ); RC522_Write_Register( ModeReg, 0x3D ); RC522_Write_Register( RxSelReg, 0x86 ); RC522_Write_Register( RFCfgReg, 0x7F ); RC522_Write_Register( TReloadRegL, 30 ); RC522_Write_Register( TReloadRegH, 0 ); RC522_Write_Register( TModeReg, 0x8D ); RC522_Write_Register( TPrescalerReg, 0x3E ); delay_us(2); RC522_Antenna_On(); } }
char PcdComMF522 ( uint8_t ucCommand, uint8_t * pInData, uint8_t ucInLenByte, uint8_t * pOutData, uint32_t * pOutLenBit ){ char cStatus = MI_ERR; uint8_t ucIrqEn = 0x00; uint8_t ucWaitFor = 0x00; uint8_t ucLastBits; uint8_t ucN; uint32_t ul;
switch ( ucCommand ) { case PCD_AUTHENT: ucIrqEn = 0x12; ucWaitFor = 0x10; break;
case PCD_TRANSCEIVE: ucIrqEn = 0x77; ucWaitFor = 0x30; break;
default: break;
}
RC522_Write_Register ( ComIEnReg, ucIrqEn | 0x80 ); RC522_ClearBit_Register ( ComIrqReg, 0x80 ); RC522_Write_Register ( CommandReg, PCD_IDLE ); RC522_SetBit_Register ( FIFOLevelReg, 0x80 );
for ( ul = 0; ul < ucInLenByte; ul ++ ) RC522_Write_Register ( FIFODataReg, pInData [ ul ] );
RC522_Write_Register ( CommandReg, ucCommand );
if ( ucCommand == PCD_TRANSCEIVE ) RC522_SetBit_Register(BitFramingReg,0x80);
ul = 1000;
do { ucN = RC522_Read_Register ( ComIrqReg ); ul --; } while ( ( ul != 0 ) && ( ! ( ucN & 0x01 ) ) && ( ! ( ucN & ucWaitFor ) ) );
RC522_ClearBit_Register ( BitFramingReg, 0x80 );
if ( ul != 0 ) { if ( ! ( RC522_Read_Register ( ErrorReg ) & 0x1B ) ) { cStatus = MI_OK;
if ( ucN & ucIrqEn & 0x01 ) cStatus = MI_NOTAGERR;
if ( ucCommand == PCD_TRANSCEIVE ) { ucN = RC522_Read_Register ( FIFOLevelReg );
ucLastBits = RC522_Read_Register ( ControlReg ) & 0x07;
if ( ucLastBits ) * pOutLenBit = ( ucN - 1 ) * 8 + ucLastBits; else * pOutLenBit = ucN * 8;
if ( ucN == 0 ) ucN = 1;
if ( ucN > MAXRLEN ) ucN = MAXRLEN;
for ( ul = 0; ul < ucN; ul ++ ) pOutData [ ul ] = RC522_Read_Register ( FIFODataReg ); } } else cStatus = MI_ERR; }
RC522_SetBit_Register ( ControlReg, 0x80 ); RC522_Write_Register ( CommandReg, PCD_IDLE );
return cStatus; }
char PcdRequest ( uint8_t ucReq_code, uint8_t * pTagType ){ char cStatus; uint8_t ucComMF522Buf [ MAXRLEN ]; uint32_t ulLen;
RC522_ClearBit_Register ( Status2Reg, 0x08 ); RC522_Write_Register ( BitFramingReg, 0x07 ); RC522_SetBit_Register ( TxControlReg, 0x03 );
ucComMF522Buf [ 0 ] = ucReq_code; cStatus = PcdComMF522 ( PCD_TRANSCEIVE, ucComMF522Buf, 1, ucComMF522Buf, & ulLen );
if ( ( cStatus == MI_OK ) && ( ulLen == 0x10 ) ) { * pTagType = ucComMF522Buf [ 0 ]; * ( pTagType + 1 ) = ucComMF522Buf [ 1 ]; } else cStatus = MI_ERR; return cStatus; }
char PcdAnticoll ( uint8_t * pSnr ){ char cStatus; uint8_t uc, ucSnr_check = 0; uint8_t ucComMF522Buf [ MAXRLEN ]; uint32_t ulLen;
RC522_ClearBit_Register ( Status2Reg, 0x08 ); RC522_Write_Register ( BitFramingReg, 0x00); RC522_ClearBit_Register ( CollReg, 0x80 );
ucComMF522Buf [ 0 ] = 0x93; ucComMF522Buf [ 1 ] = 0x20;
cStatus = PcdComMF522 ( PCD_TRANSCEIVE, ucComMF522Buf, 2, ucComMF522Buf, & ulLen);
if ( cStatus == MI_OK) { for ( uc = 0; uc < 4; uc ++ ) { * ( pSnr + uc ) = ucComMF522Buf [ uc ]; ucSnr_check ^= ucComMF522Buf [ uc ]; }
if ( ucSnr_check != ucComMF522Buf [ uc ] ) cStatus = MI_ERR; } RC522_SetBit_Register ( CollReg, 0x80 ); return cStatus; }
void CalulateCRC ( uint8_t * pIndata, u8 ucLen, uint8_t * pOutData ){ uint8_t uc, ucN;
RC522_ClearBit_Register(DivIrqReg,0x04); RC522_Write_Register(CommandReg,PCD_IDLE); RC522_SetBit_Register(FIFOLevelReg,0x80);
for ( uc = 0; uc < ucLen; uc ++) RC522_Write_Register ( FIFODataReg, * ( pIndata + uc ) );
RC522_Write_Register ( CommandReg, PCD_CALCCRC );
uc = 0xFF;
do { ucN = RC522_Read_Register ( DivIrqReg ); uc --; } while ( ( uc != 0 ) && ! ( ucN & 0x04 ) );
pOutData [ 0 ] = RC522_Read_Register ( CRCResultRegL ); pOutData [ 1 ] = RC522_Read_Register ( CRCResultRegM );
}
char PcdSelect ( uint8_t * pSnr ){ char ucN; uint8_t uc; uint8_t ucComMF522Buf [ MAXRLEN ]; uint32_t ulLen; ucComMF522Buf [ 0 ] = PICC_ANTICOLL1; ucComMF522Buf [ 1 ] = 0x70; ucComMF522Buf [ 6 ] = 0;
for ( uc = 0; uc < 4; uc ++ ) { ucComMF522Buf [ uc + 2 ] = * ( pSnr + uc ); ucComMF522Buf [ 6 ] ^= * ( pSnr + uc ); }
CalulateCRC ( ucComMF522Buf, 7, & ucComMF522Buf [ 7 ] );
RC522_ClearBit_Register ( Status2Reg, 0x08 );
ucN = PcdComMF522 ( PCD_TRANSCEIVE, ucComMF522Buf, 9, ucComMF522Buf, & ulLen );
if ( ( ucN == MI_OK ) && ( ulLen == 0x18 ) ) ucN = MI_OK; else ucN = MI_ERR;
return ucN;
}
char PcdAuthState ( uint8_t ucAuth_mode, uint8_t ucAddr, uint8_t * pKey, uint8_t * pSnr ){ char cStatus; uint8_t uc, ucComMF522Buf [ MAXRLEN ]; uint32_t ulLen;
ucComMF522Buf [ 0 ] = ucAuth_mode; ucComMF522Buf [ 1 ] = ucAddr; for ( uc = 0; uc < 6; uc ++ ) ucComMF522Buf [ uc + 2 ] = * ( pKey + uc );
for ( uc = 0; uc < 6; uc ++ ) ucComMF522Buf [ uc + 8 ] = * ( pSnr + uc ); cStatus = PcdComMF522 ( PCD_AUTHENT, ucComMF522Buf, 12, ucComMF522Buf, & ulLen ); if ( ( cStatus != MI_OK ) || ( ! ( RC522_Read_Register ( Status2Reg ) & 0x08 ) ) ) cStatus = MI_ERR;
return cStatus;
}
char PcdWrite ( uint8_t ucAddr, uint8_t * pData ){ char cStatus; uint8_t uc, ucComMF522Buf [ MAXRLEN ]; uint32_t ulLen;
ucComMF522Buf [ 0 ] = PICC_WRITE; ucComMF522Buf [ 1 ] = ucAddr;
CalulateCRC ( ucComMF522Buf, 2, & ucComMF522Buf [ 2 ] );
cStatus = PcdComMF522 ( PCD_TRANSCEIVE, ucComMF522Buf, 4, ucComMF522Buf, & ulLen );
if ( ( cStatus != MI_OK ) || ( ulLen != 4 ) || ( ( ucComMF522Buf [ 0 ] & 0x0F ) != 0x0A ) ) cStatus = MI_ERR;
if ( cStatus == MI_OK ) { for ( uc = 0; uc < 16; uc ++ ) ucComMF522Buf [ uc ] = * ( pData + uc ); CalulateCRC ( ucComMF522Buf, 16, & ucComMF522Buf [ 16 ] ); cStatus = PcdComMF522 ( PCD_TRANSCEIVE, ucComMF522Buf, 18, ucComMF522Buf, & ulLen ); if ( ( cStatus != MI_OK ) || ( ulLen != 4 ) || ( ( ucComMF522Buf [ 0 ] & 0x0F ) != 0x0A ) ) cStatus = MI_ERR; } return cStatus; }
char PcdRead ( uint8_t ucAddr, uint8_t * pData ){ char cStatus; uint8_t uc, ucComMF522Buf [ MAXRLEN ]; uint32_t ulLen;
ucComMF522Buf [ 0 ] = PICC_READ; ucComMF522Buf [ 1 ] = ucAddr; CalulateCRC ( ucComMF522Buf, 2, & ucComMF522Buf [ 2 ] ); cStatus = PcdComMF522 ( PCD_TRANSCEIVE, ucComMF522Buf, 4, ucComMF522Buf, & ulLen );
if ( ( cStatus == MI_OK ) && ( ulLen == 0x90 ) ) { for ( uc = 0; uc < 16; uc ++ ) * ( pData + uc ) = ucComMF522Buf [ uc ]; } else cStatus = MI_ERR;
return cStatus;
}
char PcdHalt( void ){ uint8_t ucComMF522Buf [ MAXRLEN ]; uint32_t ulLen;
ucComMF522Buf [ 0 ] = PICC_HALT; ucComMF522Buf [ 1 ] = 0;
CalulateCRC ( ucComMF522Buf, 2, & ucComMF522Buf [ 2 ] ); PcdComMF522 ( PCD_TRANSCEIVE, ucComMF522Buf, 4, ucComMF522Buf, & ulLen );
return MI_OK;
} ==================================================================
#ifndef _BSP_RC522_H #define _BSP_RC522_H
#include "stm32f10x.h"
#ifndef u8 #define u8 uint8_t #endif
#ifndef u16 #define u16 uint16_t #endif
#ifndef u32 #define u32 uint32_t #endif
#define RCC_GPIO RCC_APB2Periph_GPIOA #define PORT_GPIO GPIOA
#define GPIO_CS GPIO_Pin_1
#define GPIO_SCK GPIO_Pin_2
#define GPIO_MOSI GPIO_Pin_3
#define GPIO_RST GPIO_Pin_5
#define GPIO_MISO GPIO_Pin_4
#define RC522_CS_Enable() GPIO_WriteBit(PORT_GPIO, GPIO_CS,Bit_RESET) #define RC522_CS_Disable() GPIO_WriteBit(PORT_GPIO, GPIO_CS,Bit_SET)
#define RC522_Reset_Enable() GPIO_WriteBit(PORT_GPIO, GPIO_RST,Bit_RESET) #define RC522_Reset_Disable() GPIO_WriteBit(PORT_GPIO, GPIO_RST,Bit_SET)
#define RC522_SCK_0() GPIO_WriteBit(PORT_GPIO, GPIO_SCK,Bit_RESET) #define RC522_SCK_1() GPIO_WriteBit(PORT_GPIO, GPIO_SCK,Bit_SET)
#define RC522_MOSI_0() GPIO_WriteBit(PORT_GPIO, GPIO_MOSI,Bit_RESET) #define RC522_MOSI_1() GPIO_WriteBit(PORT_GPIO, GPIO_MOSI,Bit_SET)
#define RC522_MISO_GET() GPIO_ReadInputDataBit(PORT_GPIO, GPIO_MISO)
#define PCD_IDLE 0x00 #define PCD_AUTHENT 0x0E #define PCD_RECEIVE 0x08 #define PCD_TRANSMIT 0x04 #define PCD_TRANSCEIVE 0x0C #define PCD_RESETPHASE 0x0F #define PCD_CALCCRC 0x03
#define PICC_REQIDL 0x26 #define PICC_REQALL 0x52 #define PICC_ANTICOLL1 0x93 #define PICC_ANTICOLL2 0x95 #define PICC_AUTHENT1A 0x60 #define PICC_AUTHENT1B 0x61 #define PICC_READ 0x30 #define PICC_WRITE 0xA0 #define PICC_DECREMENT 0xC0 #define PICC_INCREMENT 0xC1 #define PICC_RESTORE 0xC2 #define PICC_TRANSFER 0xB0 #define PICC_HALT 0x50
#define DEF_FIFO_LENGTH 64 #define MAXRLEN 18
#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
#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
#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
#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
#define MI_OK 0x26 #define MI_NOTAGERR 0xcc #define MI_ERR 0xbb
void RC522_Init(void);
void RC522_SPI_SendByte( uint8_t byte ); uint8_t RC522_SPI_ReadByte( void ); uint8_t RC522_Read_Register( uint8_t Address ); void RC522_Write_Register( uint8_t Address, uint8_t data ); void RC522_SetBit_Register( uint8_t Address, uint8_t mask ); void RC522_ClearBit_Register( uint8_t Address, uint8_t mask );
void RC522_Antenna_On( void ); void RC522_Antenna_Off( void ); void RC522_Rese( void ); void RC522_Config_Type( char Type );
char PcdComMF522 ( uint8_t ucCommand, uint8_t * pInData, uint8_t ucInLenByte, uint8_t * pOutData, uint32_t * pOutLenBit ); char PcdRequest ( uint8_t ucReq_code, uint8_t * pTagType ); char PcdAnticoll ( uint8_t * pSnr ); void CalulateCRC ( uint8_t * pIndata, u8 ucLen, uint8_t * pOutData ); char PcdSelect ( uint8_t * pSnr ); char PcdAuthState ( uint8_t ucAuth_mode, uint8_t ucAddr, uint8_t * pKey, uint8_t * pSnr ); char PcdWrite ( uint8_t ucAddr, uint8_t * pData ); char PcdRead ( uint8_t ucAddr, uint8_t * pData ); char PcdHalt( void );
#endif ========================================================================
#include "stm32f10x.h" #include "board.h" #include "bsp_uart.h" #include "stdio.h" #include "string.h" #include "bsp_rc522.h"
u8 ucArray_ID [ 4 ]; uint8_t ucStatusReturn;
int main(void){ int i = 0;
uint8_t read_write_data[16]={0}; uint8_t card_KEY[6] ={0xff,0xff,0xff,0xff,0xff,0xff};
board_init(); uart1_init(115200U);
printf ("Init....\r\n"); RC522_Init( ); RC522_Rese( ); printf ("Start!\r\n");
while(1){
if ( ( ucStatusReturn = PcdRequest ( PICC_REQALL, ucArray_ID ) ) != MI_OK ){ ucStatusReturn = PcdRequest ( PICC_REQALL, ucArray_ID ); }
if ( ucStatusReturn == MI_OK ){ if ( PcdAnticoll ( ucArray_ID ) == MI_OK ){ printf("ID: %X %X %X %X\r\n", ucArray_ID [ 0 ], ucArray_ID [ 1 ], ucArray_ID [ 2 ], ucArray_ID [ 3 ]);
if( PcdSelect(ucArray_ID) != MI_OK ){ printf("PcdSelect failure\r\n"); }
if( PcdAuthState(PICC_AUTHENT1B, 6, card_KEY, ucArray_ID) != MI_OK ) { printf("PcdAuthState failure\r\n"); }
read_write_data[0] = 0xaa; if( PcdWrite(4,read_write_data) != MI_OK ) { printf("PcdWrite failure\r\n"); }
memset(read_write_data,0,16); delay_us(8);
if( PcdRead(4,read_write_data) != MI_OK ) { printf("PcdRead failure\r\n"); }
for( i = 0; i < 16; i++ ) { printf("%x ",read_write_data[i]); } printf("\r\n"); } } }
}
|