-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathexample.c
46 lines (36 loc) · 1.09 KB
/
example.c
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
#include "mfrc522.h"
void main() {
stdio_init_all();
// Declare card UID's
uint8_t tag1[] = {0x93, 0xE3, 0x9A, 0x92};
MFRC522Ptr_t mfrc = MFRC522_Init();
PCD_Init(mfrc, spi0);
sleep_ms(5000);
// char test_result = PCD_SelfTest(mfrc);
// if (test_result == 0) {
// printf("Self Test: SUCCESS");
// } else {
// printf("Self Test: FAILED");
// }
while(1) {
//Wait for new card
printf("Waiting for card\n\r");
while(!PICC_IsNewCardPresent(mfrc));
//Select the card
printf("Selecting card\n\r");
PICC_ReadCardSerial(mfrc);
//Show UID on serial monitor
printf("PICC dump: \n\r");
PICC_DumpToSerial(mfrc, &(mfrc->uid));
//Authorization with uid
printf("Uid is: ");
for(int i = 0; i < 4; i++) {
printf("%x ", mfrc->uid.uidByte[i]);
} printf("\n\r");
if(memcmp(mfrc->uid.uidByte, tag1, 4) == 0) {
printf("Authentication Success\n\r");
} else {
printf("Authentication Failed\n\r");
}
}
}