project van rtos

Dependencies:   mbed-os

Fork of MFRC522 by Martin Olejar

Committer:
Onon
Date:
Wed May 02 12:06:27 2018 +0000
Revision:
2:c719944e080b
Child:
3:80837b470692
init

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Onon 2:c719944e080b 1
Onon 2:c719944e080b 2 #include "mbed.h"
Onon 2:c719944e080b 3 #include "MFRC522.h"
Onon 2:c719944e080b 4
Onon 2:c719944e080b 5 //KL25Z Pins for MFRC522 SPI interface
Onon 2:c719944e080b 6 #define SPI_MOSI p5
Onon 2:c719944e080b 7 #define SPI_MISO p6
Onon 2:c719944e080b 8 #define SPI_SCLK p7
Onon 2:c719944e080b 9 #define SPI_CS p9
Onon 2:c719944e080b 10 // KL25Z Pin for MFRC522 reset
Onon 2:c719944e080b 11 #define MF_RESET p8
Onon 2:c719944e080b 12 /**
Onon 2:c719944e080b 13 // KL25Z Pins for Debug UART port
Onon 2:c719944e080b 14 #define UART_RX gnd
Onon 2:c719944e080b 15 #define UART_TX gnd
Onon 2:c719944e080b 16
Onon 2:c719944e080b 17 Serial DebugUART(UART_TX, UART_RX);
Onon 2:c719944e080b 18 **/
Onon 2:c719944e080b 19 MFRC522 RfChip(SPI_MOSI, SPI_MISO, SPI_SCLK, SPI_CS, MF_RESET);
Onon 2:c719944e080b 20 Serial pc(USBTX, USBRX);
Onon 2:c719944e080b 21
Onon 2:c719944e080b 22 DigitalOut led(LED1);
Onon 2:c719944e080b 23
Onon 2:c719944e080b 24 int main(void) {
Onon 2:c719944e080b 25 pc.printf("Start");
Onon 2:c719944e080b 26 // Set debug UART speed
Onon 2:c719944e080b 27 //DebugUART.baud(115200);
Onon 2:c719944e080b 28
Onon 2:c719944e080b 29 // Init. RC522 Chip
Onon 2:c719944e080b 30 RfChip.PCD_Init();
Onon 2:c719944e080b 31
Onon 2:c719944e080b 32 while (true) {
Onon 2:c719944e080b 33 led = 0;
Onon 2:c719944e080b 34 // Look for new cards
Onon 2:c719944e080b 35 if ( ! RfChip.PICC_IsNewCardPresent())
Onon 2:c719944e080b 36 {
Onon 2:c719944e080b 37 wait_ms(500);
Onon 2:c719944e080b 38 continue;
Onon 2:c719944e080b 39 }
Onon 2:c719944e080b 40
Onon 2:c719944e080b 41 // Select one of the cards
Onon 2:c719944e080b 42 if ( ! RfChip.PICC_ReadCardSerial())
Onon 2:c719944e080b 43 {
Onon 2:c719944e080b 44 wait_ms(500);
Onon 2:c719944e080b 45 continue;
Onon 2:c719944e080b 46 }
Onon 2:c719944e080b 47
Onon 2:c719944e080b 48 // Print Card UID
Onon 2:c719944e080b 49 pc.printf("Card UID: ");
Onon 2:c719944e080b 50 for (uint8_t i = 0; i < RfChip.uid.size; i++)
Onon 2:c719944e080b 51 {
Onon 2:c719944e080b 52 led = 1;
Onon 2:c719944e080b 53 pc.printf(" %X02", RfChip.uid.uidByte[i]);
Onon 2:c719944e080b 54 }
Onon 2:c719944e080b 55 pc.printf("\n\r");
Onon 2:c719944e080b 56
Onon 2:c719944e080b 57 // Print Card type
Onon 2:c719944e080b 58 uint8_t piccType = RfChip.PICC_GetType(RfChip.uid.sak);
Onon 2:c719944e080b 59 pc.printf("PICC Type: %s \n\r", RfChip.PICC_GetTypeName(piccType));
Onon 2:c719944e080b 60 wait_ms(1000);
Onon 2:c719944e080b 61 }
Onon 2:c719944e080b 62 }