Jump to content
43oh

RC522 Library on Stellaris


Recommended Posts

I've been trying to get this library to work with my Stellaris, which has proved a bit of a challenge for a beginner like myself..


I edited Mfrc522.cpp where I changed

Mfrc522::Mfrc522(int chipSelectPin, int NRSTPD)
{
    pinMode(chipSelectPin, OUTPUT);
    _chipSelectPin = chipSelectPin;
    pinMode(NRSTPD, OUTPUT);
    digitalWrite(NRSTPD, HIGH);
    _NRSTPD = NRSTPD;
}

to
 

Mfrc522::Mfrc522(int chipSelectPin, int NRSTPD)
{
    
    _chipSelectPin = chipSelectPin;
    
    
    _NRSTPD = NRSTPD;
}

and moved
 

    pinMode(chipSelectPin, OUTPUT);
    pinMode(NRSTPD, OUTPUT);
    digitalWrite(NRSTPD, HIGH);

to setup (void) of the sketch.

NERDGASM! only took about 10 hrs, but I have a card read! fk yeah!

For my setup I've set
 

int chipSelectPin = 2;  //SDA on reader - connected to pin2 aka CS(2)
int NRSTPD = 17; // aka PF_0

I've found out that
 

Mfrc522 Mfrc522(chipSelectPin,NRSTDP);

doesnt match Mfrc522.cpp, where the variable NRSTPD is used, so I changed NRSTDP to NRSTPD in the sketch.


here is my working code:

/*
    Example file for communicating with the NFRC522. The program prints the card data.
    Created by Eelco Rouw - Originally adapted by Grant Gibson.
    Modified by phaseform for use with the Stellaris
*/


// pin mapping for SPI(2) on the Stellaris (also tiva??) using Rei Vilo's pinmap
// SDA  -  CS(2) -> PB_5 = pin 2 as an integer
// SCK  -  SCK(2) -> PB_4
// Mosi -  MOSI(2) -> PB_7
// Miso -  MISO(2) -> PB_6
// IRQ  - Not connected
// GND  - GND
// RST  - reset -> PF_0
// VCC  - +3.3V = pin 1

#include <Mfrc522.h>
#include <SPI.h>

int chipSelectPin = 2;  //SDA on reader - connected to pin2 aka CS(2)
int NRSTPD = 17; //aka PF_0
Mfrc522 Mfrc522(chipSelectPin, NRSTPD); //changed NRSTDP to NRSTPD
unsigned char serNum[5];

void setup()
{  
        Serial.begin(9600);      // using serial port 1 (USB)      
        SPI.setModule(2); // using SPI module 2...
        pinMode(chipSelectPin, OUTPUT); //moved this here from Mfrc522.cpp
        digitalWrite(chipSelectPin, LOW);
        pinMode(NRSTPD, OUTPUT); //moved this here from Mfrc522.cpp
        digitalWrite(NRSTPD, HIGH); //moved this here from Mfrc522.cpp
        pinMode(BLUE_LED, OUTPUT);
        pinMode(RED_LED, OUTPUT);
        Mfrc522.Init();
}

void loop()
{
    unsigned char i,tmp;
    unsigned char status;
    unsigned char str[MAX_LEN];
    unsigned char RC_size;
    unsigned char blockAddr;
    String mynum = "";
      
    status = Mfrc522.Request(PICC_REQIDL, str);    
    if (status == MI_OK)
    {
        Serial.println("Card detected");
        Serial.print(str[0],BIN);
        Serial.print(" , ");
        Serial.print(str[1],BIN);
        Serial.println(" ");
                digitalWrite(BLUE_LED, HIGH);
                delay(1000);
                digitalWrite(BLUE_LED, LOW);
    }
else{
                digitalWrite(RED_LED, HIGH);                
                Serial.println("no dice here");
                delay(1000);
                digitalWrite(RED_LED, LOW);
}

    status = Mfrc522.Anticoll(str);
    memcpy(serNum, str, 5);
    if (status == MI_OK)
    {
                digitalWrite(BLUE_LED, HIGH);
                delay(1000);
                digitalWrite(BLUE_LED, LOW);
        Serial.println("The card's number is  : ");
        Serial.print(serNum[0]);
        Serial.print(" , ");
        Serial.print(serNum[1],BIN);
        Serial.print(" , ");
        Serial.print(serNum[2],BIN);
        Serial.print(" , ");
        Serial.print(serNum[3],BIN);
        Serial.print(" , ");
        Serial.print(serNum[4],BIN);
        Serial.println(" ");

        // Should really check all pairs, but for now we'll just use the first

        if(serNum[0] == 29)
        {
            Serial.println("Hello Eelco");
            digitalWrite(BLUE_LED, HIGH);
            delay(1000);
            digitalWrite(BLUE_LED, LOW);
        }     
        delay(1000);    
    }
        else{
                digitalWrite(RED_LED, HIGH);
                Serial.println("no dice");
                delay(1000);
                digitalWrite(RED_LED, LOW);
        }


    Mfrc522.Halt();       
}
Link to post
Share on other sites
  • 1 month later...

I have the same problem, it seems that the permission to download attachments is granted when you made a specific amount of postings to the forum. i think you need about 3-5 postings.
Well its hard for a beginner to post or reply something meaningful with the limited knowledge of a beginner.
 

regards, Nick

Link to post
Share on other sites

I have the same problem, it seems that the permission to download attachments is granted when you made a specific amount of postings to the forum. i think you need about 3-5 postings.

Well its hard for a beginner to post or reply something meaningful with the limited knowledge of a beginner.

I totally agree. While I am not new to SW/HW work, I just started using the Tiva-C Launchpad and have very little to share yet.

Let's try "increasing" my post count to 3-5 :), and see what happens...

Link to post
Share on other sites

@@bluehash, do users indeed have to have a certain amount of posts to be able to download files? Is that something we can turn off?

 

 

Same question here...

 

 

I totally agree. While I am not new to SW/HW work, I just started using the Tiva-C Launchpad and have very little to share yet.

Let's try "increasing" my post count to 3-5 :), and see what happens...

 

 

Interesting, the downloadable files in the "code vault" forum section are accessible. But the ones in the energia section are not

 

 

Nope, 5 posts did not work. I give up...

 

 

Me neither, when i archive enough posts to download attachments i'll let you know.

 

Sorry for the trouble everyone. It has been fixed. Please double check and let me know.

Again apologies.

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.

Guest
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...