Initialize RC522 RFID module

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

Hello everybody,

I have a problem with initializing rc522 module. Im using AVR studio, ATmega32A and im programming in C. I want SPI to communicate between atmega and rc522. is there something i sould send to the rc255 before start communication? here is my test code - i want to find out version of SW, it should be 91 or 92 according to datasheet, but it sends back only 0x00 to the terminal .. it seems no communication here :(
some advice please... 
RST pin is connected to rst of atmega and SS pin is to gnd
 

int main(void)
{
//sei();
UBRRL = 77;										// set baudrate
UBRRH = 0;
UCSRB |= (1<<TXEN)|(1<<RXEN)|(1<<RXCIE);				// enable receiver and transmitter
UCSRC |= (1<<URSEL) | (1<<UCSZ0)|(1<<UCSZ1);							// 8bit data format
DDRD |= 0b00000010;	//TXD RXD

DDRB|=(1<<5)|(1<<7);  //mosi and sck is output
SPCR = (1 << SPE) | (1 << MSTR) | (1 << SPR0) | (1 << SPIE); //spi settings



SPDR=0XB6;    //want to read from address 0x37
_delay_ms(1000);

UDR=SPDR;    //send data from rc522 to terminal


while (1);

}

 

This topic has a solution.
Last Edited: Thu. Aug 10, 2017 - 09:10 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Please post a link to the datasheet for your rc522.

My guess is your not talking to it correctly!  SPI is a full duplex comm, so it reads/writes at the same time.

When you send a command to the device, it needs to process that command, so you wait, then you send something to it so it can respond back.

 

Your program only sends once, waits, and some how expects the data to magically appear in the SPDR register without sending anything to the RC522.

Read the data sheet and see what you need to do to receive data from the device.

 

 

Jim

 

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

There must be a gazillion arduino projects using the RC522 you can look at to see how it works.

 

Jim

 

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

ki0bk wrote:
There must be a gazillion arduino projects using the RC522 you can look at to see how it works.

First Google hit:  https://playground.arduino.cc/Le...

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

OoO wrote:
RST pin is connected to rst of atmega and SS pin is to gnd

Why in the world would you start out doing it that way?!?

 

Why do you think there is a slave-select on SPI devices?  If you always keep it enabled, then if you ever get out of sync you will never re-sync.  Consider a false SCK pulse at startup, for example.

 

You enable an SPI interrupt, but have no ISR.  Not a good thing.

 

Have you tested your USART connection with a startup message?

 

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

Do you have the chip configured for SPI?   i.e. pin 12c low, pin EA high, what M32 pin are you using for SS (NSS)?  Can you show us your schematic on how you have it wired?

 

Read section: 8.1.2 SPI to see what you must send to the 522 in order to read/write data to/from it.  Your test program does none of that.....

 

An Arduino UNO is great to have on hand to test new devices, as you can find a demo sketch for most devices, and makes testing your h/w easy and verify it's operation.

 

Jim

 

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

Okay, i will connect ss to ss
Yes, here is interrupt enable cuz i was using it than i changed the code, i will fix it
And USART works well, i tested it..

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

OoO wrote:
UBRRL = 77; // set baudrate

That is a very interesting UBRR value.  I cannot remember seeing that before.  9600bps at 12MHz AVR clock?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

I2c pin and ae pin are ok
Here is connecting..
https://home.ctw.utwente.nl/slootenvanf/wp-content/uploads/2016/05/RFID-RC522-pinout.png
I connected ss on module to ss on atmega, mosi on module to mosi on atmega and so on, except irq pin, this one is disconnected

And the addressing.. address what i want to read from is 37h .. and i used this calculation
0x80 | (Address & 0x7E) ..i find it somewhere on the internet

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

Whats the interesting on that UBBR value? Is works well..