project van rtos
Dependencies: mbed-os
Fork of MFRC522 by
Diff: main.cpp
- Revision:
- 2:c719944e080b
- Child:
- 3:80837b470692
diff -r 63d729186747 -r c719944e080b main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed May 02 12:06:27 2018 +0000 @@ -0,0 +1,62 @@ + +#include "mbed.h" +#include "MFRC522.h" + +//KL25Z Pins for MFRC522 SPI interface +#define SPI_MOSI p5 +#define SPI_MISO p6 +#define SPI_SCLK p7 +#define SPI_CS p9 +// KL25Z Pin for MFRC522 reset +#define MF_RESET p8 +/** +// KL25Z Pins for Debug UART port +#define UART_RX gnd +#define UART_TX gnd + +Serial DebugUART(UART_TX, UART_RX); +**/ +MFRC522 RfChip(SPI_MOSI, SPI_MISO, SPI_SCLK, SPI_CS, MF_RESET); +Serial pc(USBTX, USBRX); + +DigitalOut led(LED1); + +int main(void) { + pc.printf("Start"); + // Set debug UART speed + //DebugUART.baud(115200); + + // Init. RC522 Chip + RfChip.PCD_Init(); + + while (true) { + led = 0; + // Look for new cards + if ( ! RfChip.PICC_IsNewCardPresent()) + { + wait_ms(500); + continue; + } + + // Select one of the cards + if ( ! RfChip.PICC_ReadCardSerial()) + { + wait_ms(500); + continue; + } + + // Print Card UID + pc.printf("Card UID: "); + for (uint8_t i = 0; i < RfChip.uid.size; i++) + { + led = 1; + pc.printf(" %X02", RfChip.uid.uidByte[i]); + } + pc.printf("\n\r"); + + // Print Card type + uint8_t piccType = RfChip.PICC_GetType(RfChip.uid.sak); + pc.printf("PICC Type: %s \n\r", RfChip.PICC_GetTypeName(piccType)); + wait_ms(1000); + } +}