Jump to content

[Energia Library] NFC card reading with Energia - MF RC 522

Recommended Posts

Hi @@Thinhnguyenky and welcome to 43oh...


The library for the card reader has a number of functions that allow the user to access and use the device.


Mfrc522 Mfrc522(chipSelectPin,NRSTDP); - creates a new instance named Mfrc522 that can be used to access the library

Mfrc522.Init();" - initializes the device using the instance specified above

Mfrc522.Request(PICC_REQIDL, str); - requests information from the card reader


The examples give simplified code that demonstrates how they work.


If you need a beginner's guide on how a library works see this: http://energia.nu/guide/tutorial_library/


If you would like to see the specific code and documentation associated with these functions then look in the .cpp and .h files that come with the library.

Share this post

Link to post
Share on other sites

Hi everyone,Is it possible this source code and libraries are adapted for MSP432P401R ? If it is,how can I do please explain for me..


I have MSP430,432 and RC552.This code is running on MSP430 but I want to run on MSP432.


Thanks for supports.

Share this post

Link to post
Share on other sites

Maybe it will help someone. You can use arduino's library https://github.com/miguelbalboa/rfid with Energia. All that you need is comment out all SPI.beginTransaction and SPI.endTransaction lines in MFRC522.cpp, and also define SS constant (SDA/chip select pin number, #define SS 8 in my case) in the same file.


After this library itself and library exambles are working at least on Tiva C launchpad.

Share this post

Link to post
Share on other sites
On 17.08.2013 at 3:34 AM, D69 said:

OK, spent a bit of time on this this evening.

Tried knocking together some code to allow hard coding of tag IDs which works OK. Might need to change the for loop though as anything in else just gets repeated, a switch might do the trick but it's late.

For anyone interested, here's my code, would appreciate any improvements that could be made, including an scenario where the tag's not recognized as valid.

	Example file for communicating with the NFRC522. The program prints the card data.
	Created by Eelco Rouw - Originally adapted by Grant Gibson. 

// Pinout
// SDA  - 2.2
// SCK  - 1.5
// Mosi - 1.7
// Miso - 1.6
// IRQ  - NC
// GND  - GND
// RST  - 1.3
// VCC  - VCC

#include <Mfrc522.h>

// the sensor communicates using SPI, so include the library:
#include <SPI.h>

int chipSelectPin = 10;
int NRSTDP = 5;
int ledpin1 = 3;
int ledpin2 = 6;
int cardint = 5;

Mfrc522 Mfrc522(chipSelectPin,NRSTDP);
unsigned char serNum[5];
unsigned char sectorKey[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
unsigned char readData[16];

void setup() 
	Serial.begin(9600);                       // RFID reader SOUT pin connected to Serial RX pin at 2400bps 
	// Start the SPI library:
	// Initialize the Card Reader
	digitalWrite(chipSelectPin, LOW);
	pinMode(RED_LED, OUTPUT);
        pinMode(ledpin1, OUTPUT);
        pinMode(ledpin2, OUTPUT);

void loop()
	unsigned char i,tmp;
	unsigned char status;
	unsigned char str[MAX_LEN];
	unsigned char RC_size;
	unsigned char blockAddr;
	//String mynum = "";
        String mycardno;
        char* myarray[2][5]={  //Array of tags and related names, tag numbers copied from serial console after 1s
	status = Mfrc522.Request(PICC_REQIDL, str);	
	if (status == MI_OK)
		Serial.println("Card detected");
		Serial.print(" , ");
		Serial.println(" ");

	status = Mfrc522.Anticoll(str);
	memcpy(serNum, str, 5);
	if (status == MI_OK)
		Serial.println("The card's number is  : ");
		Serial.print(serNum[0], DEC);
		Serial.print(" , ");
		Serial.print(serNum[1], DEC);
		Serial.print(" , ");
		Serial.print(serNum[2], DEC);
		Serial.print(" , ");
		Serial.print(serNum[3], DEC);
		Serial.print(" , ");
		Serial.print(serNum[4], DEC);
		Serial.println(" ");
                mycardno = String(serNum[0]) += String(serNum[1]) += String(serNum[2]) += String(serNum[3]) += String(serNum[4]); // Appends the content of the serNum array to give a unique card no
                status = Mfrc522.Auth(PICC_AUTHENT1A,1,sectorKey,serNum);
                if (status == MI_OK)
                } else
                  Serial.println("Error authenticating...\r\n");
                status = Mfrc522.ReadBlock(1, readData);
                if (status == MI_OK)
                  for(i=0; i<16; i++)
                } else {
                  Serial.println("Error reading.");
                int i;
                for(i = 0; i < 5; i = i + 1)
                  if (mycardno == myarray[0][i])
                  Serial.print("Hello ");
                  Serial.println(myarray[1][i]);        // Should Print out name matching tag
                /*else {
                  Serial.println("Bugger Off");
	//Serial.println(" ");


Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...