5 years, 8 months ago.

How to send data byte in RFID MFRC522 and how to read from it?

<<MFRC522>>

This is my program to write and read from Rc522. I send slave address and register address but how do I send data byte ( char data, or char data = 0x00,or specifi address) and how do I read from the register.

  1. include <<mbed.h>> <</
  1. define F_CPU 16000000UL
  2. include <avr/io.h>
  3. include <string.h>
  4. include <inttypes.h>
  1. define SDA PC0
  2. define SCL PC1
  1. include "Lcd.avr.h"
  2. include "I2C.avr.h"
  3. include "i2cmaster.h" #include "Rfid.h"
  1. define Write_Address 0x50 slave addres+ write
  2. define commadstart 0x01
  3. define FIFO_Data 0x09
  4. define I2c_write 0 write bit
  5. define I2c_read 1 read bit

unsigned char DATA; /*what data byte is written to internal register address */ unsigned char data[64]; void Rfid_Start() { i2c_init(); i2c_start(Write_Address+I2c_write); i2c_write(FIFO_Data); Address to write internal register i2c_stop(); }

unsigned char Rfid_get_data(char read_address) {

i2c_start(Write_Address+I2c_write); i2c_write(FIFO_Data); _delay_ms(1); i2c_rep_start(Write_Address+I2c_read); DATA= i2c_readNak(); /*how to read data from slave */ i2c_stop(); return DATA;

}

int main() {

DDRB = 0xFF; lcd_init(); _delay_ms(100); LCD_String_xy(0,0); lcdprint("Show your card:"); Rfid_Start(); while(1) { Rfid_get_data(0x0A); data[64] = DATA; LCD_String_xy(0,1); dis_cmd(0x01); for (int i=0;i<65;i++) { lcd_int(data[i]); } }

}

Be the first to answer this question.