RFID MFRC522 module READING UID

Go To Last Post
10 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

so , I want to do a project to read this MFRC522 Arduino sensor using ATMEL studio 7 , I use the Arduino uno microcontroller ATMEGA328P , for now I initialized the SPI communication , this is the function 

 

void SPI_init()
{
    DDRB = (1<<3) | (1<<5) | (1<<2); // mosi , sck , ss high
    
    SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0);
    
}

unsigned char SPI_MasterTransmit(unsigned char cData)
{
    /* Start transmission */
    
    SPDR = cData;
    
    /* Wait for transmission complete */
    
    while(!(SPSR & (1<<SPIF)));
    
    return SPDR;
    
}

 

and I found a MFRC522.h library file on the AVR lib site , I will attach it here  if I can 

the question is , what functions do I need to write for this RC522.h file , I mean for the RC522.c to use the functions from RC522.h  

ANY HELP WOULD BE HIGHLY APPRECIATED , maybe someone did this project or something like this and can help with info . 

Attachment(s): 

This topic has a solution.
Last Edited: Thu. Jul 18, 2019 - 11:06 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The h file has no code. Where did you get it from so we can actually look at the code?

 

Note - Studio 7 can load Arduino projects. Why do you not want to use Arduino?

 

Last Edited: Thu. Jul 18, 2019 - 10:02 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

http://randomport.com/doxygen/av...

 

this is the .h code , and know i'm trying to write the functions in the .c file from this .h file 

it is a work project and I need to do this in atmel .. I wish I can use Arduino but no 

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

The actual code seems to be at:  http://randomport.com/pages/avr-library.html

 

That in turn directs you to:  https://github.com/matejx/avr_lib

 

There you find:

 

https://github.com/matejx/avr_lib/blob/master/mfrc522.h  (that you have above)

 

but also:

 

https://github.com/matejx/avr_lib/blob/master/mfrc522.c

 

which seems to be the bit you are missing. That in turn seems to be (at least) dependent on:

 

https://github.com/matejx/avr_lib/blob/master/spi.h

https://github.com/matejx/avr_lib/blob/master/spi.c

 

all of those are in turn dependent (at least) on hwdefs.h and swdefs.h. This is where this may get "tricky". I can see hwdefs_minimal.h at:

 

https://github.com/matejx/avr_lib

 

but no sign of any swdefs.h?? I guess all you can do is pull some/all files - try to build the mfrc522 support and see what it complains about being missing.

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

PS this *might* work or it might not. Looking in Github at the author's other projects I see:

 

https://github.com/matejx/ser2hd44780

 

That has both hwdfes.h and swdefs.h.

 

Now whether those are the right versions of the files or not is another question!

 

(actually looking at the contents it all seems to be about an LCD so maybe you don't need swdefs.h at all? And for hwdefs use the hwdefs_iminal.h in his avr_lib).

 

PS if all that does not work out for you there's another AVR/MFRC522 lib in Github at:  https://github.com/asif-mahmud/MIFARE-RFID-with-AVR/tree/master/lib (scrappy indentation probably suggests it is not very good though!))

Last Edited: Thu. Jul 18, 2019 - 11:02 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thanks I just needed some examples on how to build that mfrc522.c , actually I need just the important function for reading a UID , and I try to build myself this file being helped by that MFRC522.h where the functions are declared . Hope that I will do something about that , I really appreciate your help .  

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

can you explain how this is set here?

 

 mfrc522_write(TModeReg, 0x8D);

  mfrc522_write(TPrescalerReg, 0x3E);

 

I found the registers in datasheet and these 2 registers , last 4 bits from TModeReg and TPrescalerReg are making a 12bit prescaler  and it is 36158 binary value 

the formula says ftimer = 13.56 Mhz / (2*Tprescaler(36158)+1) and i get 187.500 and i think it s wrong , the formula it s in the mfrc522 datasheet page 62

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You'd be far better off contacting those code authors on Github. If they have got the MFRC522 to work they have presumably faced and fixed any such issues?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

the code autor is not active since 2017 or so , I don't think they are wrong just I think I don t understand 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

36158 will not fit into a 12 bit value. According to your interpretation of the datasheet the hex value is 0xd3e which is 3390 decimal. Or is it 0x83e? i’ve not read the datasheet, so i’ll leave it to you.