Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
- Committer:
- adarsh575
- Date:
- 2020-01-10
- Revision:
- 1:037eeb07f3fc
- Parent:
- 0:35581ea6b194
- Child:
- 2:fa941f0137b3
File content as of revision 1:037eeb07f3fc:
/* mbed Microcontroller Library
* Copyright (c) 2018 ARM Limited
* SPDX-License-Identifier: Apache-2.0
*/
#include "mbed.h"
#include "MFRC522.h"
#define SLEEP_TIME 500 // (msec)
#define PRINT_AFTER_N_LOOPS 20
// K64F Pin for "MFRC522 (Chip select, Clock, MOSI, MISO, IRQ, Ground, Reset, 3.3V)"
#define MF_RESET D9 //Reset
#define SPI_MOSI p5 //MOSI
#define SPI_MISO p6 //MISO
#define SPI_SCK p7 //Clock
#define SPI_CS p8 //Chip Select
DigitalOut LedGreen(LED1);
Serial pc(USBTX, USBRX);
MFRC522 RfChip (SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, MF_RESET);
// main() runs in its own thread in the OS
int main()
{
pc.baud(9600);
pc.printf("\r\n*********************Initialization**********************************");
RfChip.PCD_Init(); /* Init. RC522 Chip*/
pc.printf("\r\n**********************Starting Reading Tags**************************");
while (true) {
LedGreen = 1;
if ( ! RfChip.PICC_IsNewCardPresent())
{
wait_ms(500);
continue;
}
// Select one of the cards
if (!RfChip.PICC_ReadCardSerial())
{
wait_ms(500);
pc.printf("\r\nReading a card");
continue;
}
LedGreen = 0;
// Print Card UID
pc.printf("\r\nCard UID: ");
for (uint8_t i = 0; i < RfChip.uid.size; i++)
{
pc.printf(" %X02", RfChip.uid.uidByte[i]);
}
pc.printf("\r\n");
// Print Card type
uint8_t piccType = RfChip.PICC_GetType(RfChip.uid.sak);
pc.printf("PICC Type: %s \r\n", RfChip.PICC_GetTypeName(piccType));
wait_ms(1000);
}
}