RFID rc522 reading using atmega328p from arduino uno in atmel studio

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

#ifndef F_CPU
#define F_CPU 16000000UL //16 Mhz clock speeed
#endif

#include <avr/io.h>
#include <util/delay.h>
/*DEFINE SPI PINS */

 

void spi_init_master(void)
{
    DDRB = (1<<5) | (1<<3); //mosi,sck output
      // Enable SPI, Set as Master
      // Prescaler: Fosc/16, Enable Interrupts
    SPCR = (1<<SPIE) | (1<<SPE) | (1<<MSTR)|(1<<SPR0);  
    
    
}
unsigned char spi_transceiver(unsigned char dataout)
{
    unsigned char datain;
    //LOAD DATA in the buffer
    SPDR=dataout;
    //wait until transmission complete
    while(!((SPSR)&(1<<SPIF)))
    //return received data
    datain=SPDR;
    
    return datain;
}

int main(void)

{
    unsigned char cnt;
    DDRD=0xFF;
    PORTD=0x00;
    spi_init_master();
    
    cnt = spi_transceiver(0);
    for(;;) {
        cnt=1;
        while(cnt) {
            cnt=cnt<<1;
            PORTD=spi_transceiver(cnt);
            _delay_ms(100);
        }
        cnt=0x80;
        while(cnt) {
            cnt=cnt>>1;
            PORTD=spi_transceiver(cnt);
            _delay_ms(100);
        }
    }
     
   return 0;
}

 

 

 

If somebody could help me read this module or can say what i'm doing wrong thanks 

 

This topic has a solution.
Last Edited: Wed. Jul 17, 2019 - 02:37 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Welcome to AVRFreaks!

 

Google is your friend for arduino projects, must be a TON of tutorials if you enter "Arduino rc522"!

 

Here is a top hit.  https://randomnerdtutorials.com/...

Hope it helps.

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

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

ki0bk wrote:

Welcome to AVRFreaks!

 

Google is your friend for arduino projects, must be a TON of tutorials if you enter "Arduino rc522"!

 

Here is a top hit.  https://randomnerdtutorials.com/...

Hope it helps.

Jim

 

I do not want to use Arduino for this project

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

undercover00 wrote:

ki0bk wrote:

Welcome to AVRFreaks!

 

Google is your friend for arduino projects, must be a TON of tutorials if you enter "Arduino rc522"!

 

Here is a top hit.  https://randomnerdtutorials.com/...

Hope it helps.

Jim

 

I do not want to use Arduino for this project

undercover00 wrote:

ki0bk wrote:

Welcome to AVRFreaks!

 

Google is your friend for arduino projects, must be a TON of tutorials if you enter "Arduino rc522"!

 

Here is a top hit.  https://randomnerdtutorials.com/...

Hope it helps.

Jim

 

I do not want to use Arduino for this project

You don't have to. A lot of Arduini are 328P anyway, IIRC. And the source is likely on Github somewhere. Remember Arduino is just C(++).

 

Four legs good, two legs bad, three legs stable.

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

Even if you don't want to use Arduino ultimately, there is nothing wrong with using it to verify your hardware is wired correctly and works as expected.

Then you can write your own code with the knowledge you don't have to troubleshoot both the software and hardware, saves a lot of head scratching! smiley

 

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

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

does anyone know where I can find some libraries for the RC522 rfid sensor or something? I find it hard to do all the libraries and things , to read that UID from card , for now I just initialized SPI  but I don't know what to do next it's too much information everywhere but no examples or so , any help would be appreciated

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


Didn't Jim give you a clue in #2 ? I would have thought that the picture:

 

 

would pique your interest as it appears there code has achieved exactly what you wanted to do (read the UID). There is a link to their code as a .zip file there but using that URL you can work back to the parent directory which is:

 

https://github.com/miguelbalboa/rfid/

 

and that lets you explore the code.