/*############################################################# Program Name : ex1_F446RE_RDM6300_RFID Author : Grant Phillips Date Modified : 18/09/2016 Compiler : ARMmbed Tested On : NUCLEO-F446RE Description : Example program that demonstrates the use of the RDM6300 RFID Reader. (https://www.itead.cc/wiki/RDM6300) Requirements : * NUCLEO-F446RE Board Circuit : * The RDM6300 RFID Reader connected as: P3 1. LED - Not connected 2. +5V - +5V 3. GND - GND P2 1. ANT1 - Ext. antenna RED 2. ANT2 - Ext. antenna BLACK P1 1. TX - PA_10 (Serial1_RX) 2. RX - Not connected 3. N/A - Not connected 4. GND - Not connected 5. +5V - Not connected ##############################################################*/ #include "mbed.h" Serial pc(SERIAL_TX, SERIAL_RX); //to use the PC as a console (display output) Serial rfid(PA_9, PA_10); //connection to RDM6300 RFID Reader DigitalOut led1(PA_5); //led to indicate when a tag was read //Just a sample of a rfid tag. Tags always start with 0x02, ends with 0x03, and contains 14 8-bit values (bytes) unsigned char MagicRFIDCard[] = {0x02, 0x31, 0x31, 0x30, 0x30, 0x34, 0x38, 0x33, 0x43, 0x31, 0x41, 0x37, 0x46, 0x03}; unsigned char tagRX[14]; //array to store incoming tag int tagRXindex=0; //keeps track of the index in tagRX bool tagIncomingFlag=false; //flag to indicate that a new tag is busy being read bool newtagFlag=false; //flag to indicate that a new tag was finished being read //interrupt routine to service incomeing RFID values void rfidinterrupt() { unsigned char rxByte; rxByte = rfid.getc(); //read character from serial port if ((tagIncomingFlag == false) && (rxByte == 0x02)) { //start of a new RFID sequence tagRX[tagRXindex] = rxByte; tagIncomingFlag = true; tagRXindex++; } else if (tagIncomingFlag == true) { //valid incoming RFID sequence tagRX[tagRXindex] = rxByte; tagRXindex++; if (tagRXindex == 14) { tagRXindex = 0; tagIncomingFlag = false; newtagFlag = true; } } else { //invalid incomeing characters tagIncomingFlag = false; tagRXindex = 0; } } int main() { int i; rfid.attach(&rfidinterrupt); //initialize serial port interrupt pc.printf("RDM6300 RFID Reader example program\n"); while(1) { if(newtagFlag == true) { //a new RFID tag was read led1=1; pc.printf("New tag received: "); for(i=0; i<14; i++) { //display all 14 RFID values pc.printf("%2X ", tagRX[i]); } pc.printf("\n"); if (memcmp(tagRX, MagicRFIDCard, 14) == 0) { //compare the first 14 bytes of the received RFID array to another array pc.printf("Congratulations, Magic Card was detected!\n"); } wait(0.5); //small delay to prevent repeated card reading led1=0; newtagFlag = false; //clear the flag after the new RFID tag was serviced } } }