Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
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.
- include
<<mbed.h>>
<</
- define F_CPU 16000000UL
- include <avr/io.h>
- include <string.h>
- include <inttypes.h>
- define SDA PC0
- define SCL PC1
- include "Lcd.avr.h"
- include "I2C.avr.h"
- include "i2cmaster.h" #include "Rfid.h"
- define Write_Address 0x50 slave addres+ write
- define commadstart 0x01
- define FIFO_Data 0x09
- define I2c_write 0 write bit
- 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]); } }
}