card rfid 13.56 1k - Page 1
Forum section: electronics / general

author: Adrian_Arg.
author_rank: Frequent Contributor
timestamp: September 01, 2018, 11:53:24 pm
content: hello, I have an mrfc522 module and rfid 13.56 cards with 1 kb capacity, I'm using it with an arduino one, the problem is that I can only record 30 characters and I do not know why, any suggestion because only 30 characters.in spanishhola, tengo un modulo mrfc522 y tarjetas rfid 13.56 con 1 kb de capacidad, la estoy usando con un arduino uno, el problema es que solo puedo grabar 30 caracteres y no se porque, alguna sugerencia de porque solo 30 caracteres.

author: SiliconWizard
author_rank: Super Contributor
timestamp: September 02, 2018, 09:31:55 pm
content: I have never used the MFRC522 (but have used NFC before), but I would guess you don't handle the incoming data buffering correctly?Apparently it has a 64-byte buffer but without knowing any more about your own code, that would be hard to guess what could be wrong.Have you tried reading the status registers (Status1Reg...) to figure out the FIFO state?

author: Adrian_Arg.
author_rank: Frequent Contributor
timestamp: September 03, 2018, 12:32:15 am
content: this is the code i useCode:/** Write personal data of a MIFARE RFID card using a RFID-RC522 reader* Uses MFRC522 - Library to use ARDUINO RFID MODULE KIT 13.56 MHZ WITH TAGS SPI W AND R BY COOQROBOT.* -----------------------------------------------------------------------------------------* MFRC522 Arduino Arduino Arduino Arduino Arduino* Reader/PCD Uno/101 Mega Nano v3 Leonardo/Micro Pro Micro* Signal Pin Pin Pin Pin Pin Pin* -----------------------------------------------------------------------------------------* RST/Reset RST 9 5 D9 RESET/ICSP-5 RST* SPI SS SDA(SS) 10 53 D10 10 10* SPI MOSI MOSI 11 / ICSP-4 51 D11 ICSP-4 16* SPI MISO MISO 12 / ICSP-1 50 D12 ICSP-1 14* SPI SCK SCK 13 / ICSP-3 52 D13 ICSP-3 15** Hardware required:* Arduino* PCD (Proximity Coupling Device): NXP MFRC522 Contactless Reader IC* PICC (Proximity Integrated Circuit Card): A card or tag using the ISO 14443A interface, eg Mifare or NTAG203.* The reader can be found on eBay for around 5 dollars. Search for "mf-rc522" on ebay.com.*/#include <SPI.h>#include <MFRC522.h>#define RST_PIN 9 // Configurable, see typical pin layout above#define SS_PIN 10 // Configurable, see typical pin layout aboveMFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instancevoid setup() {Serial.begin(9600); // Initialize serial communications with the PCSPI.begin(); // Init SPI busmfrc522.PCD_Init(); // Init MFRC522 cardSerial.println(F("Write personal data on a MIFARE PICC "));}void loop() {// Prepare key - all keys are set to FFFFFFFFFFFFh at chip delivery from the factory.MFRC522::MIFARE_Key key;for (byte i = 0; i < 6; i++) key.keyByte = 0xFF;// Look for new cardsif ( ! mfrc522.PICC_IsNewCardPresent()) {return;}// Select one of the cardsif ( ! mfrc522.PICC_ReadCardSerial()) {return;}Serial.print(F("Card UID:")); //Dump UIDfor (byte i = 0; i < mfrc522.uid.size; i++) {Serial.print(mfrc522.uid.uidByte < 0x10 ? " 0" : " ");Serial.print(mfrc522.uid.uidByte, HEX);}Serial.print(F(" PICC type: ")); // Dump PICC typeMFRC522::PICC_Type piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);Serial.println(mfrc522.PICC_GetTypeName(piccType));byte buffer;byte block;MFRC522::StatusCode status;byte len;Serial.setTimeout(20000L) ; // wait until 20 seconds for input from serial// Ask personal data: Family nameSerial.println(F("Type Family name, ending with #"));len = Serial.readBytesUntil('#', (char *) buffer, 30) ; // read family name from serialfor (byte i = len; i < 30; i++) buffer = ' '; // pad with spacesblock = 1;//Serial.println(F("Authenticating using key A..."));status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, &key, &(mfrc522.uid));if (status != MFRC522::STATUS_OK) {Serial.print(F("PCD_Authenticate() failed: "));Serial.println(mfrc522.GetStatusCodeName(status));return;}else Serial.println(F("PCD_Authenticate() success: "));// Write blockstatus = mfrc522.MIFARE_Write(block, buffer, 16);if (status != MFRC522::STATUS_OK) {Serial.print(F("MIFARE_Write() failed: "));Serial.println(mfrc522.GetStatusCodeName(status));return;}else Serial.println(F("MIFARE_Write() success: "));block = 2;//Serial.println(F("Authenticating using key A..."));status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, &key, &(mfrc522.uid));if (status != MFRC522::STATUS_OK) {Serial.print(F("PCD_Authenticate() failed: "));Serial.println(mfrc522.GetStatusCodeName(status));return;}// Write blockstatus = mfrc522.MIFARE_Write(block, &buffer, 16);if (status != MFRC522::STATUS_OK) {Serial.print(F("MIFARE_Write() failed: "));Serial.println(mfrc522.GetStatusCodeName(status));return;}else Serial.println(F("MIFARE_Write() success: "));// Ask personal data: First nameSerial.println(F("Type First name, ending with #"));len = Serial.readBytesUntil('#', (char *) buffer, 20) ; // read first name from serialfor (byte i = len; i < 20; i++) buffer = ' '; // pad with spacesblock = 4;//Serial.println(F("Authenticating using key A..."));status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, &key, &(mfrc522.uid));if (status != MFRC522::STATUS_OK) {Serial.print(F("PCD_Authenticate() failed: "));Serial.println(mfrc522.GetStatusCodeName(status));return;}// Write blockstatus = mfrc522.MIFARE_Write(block, buffer, 16);if (status != MFRC522::STATUS_OK) {Serial.print(F("MIFARE_Write() failed: "));Serial.println(mfrc522.GetStatusCodeName(status));return;}else Serial.println(F("MIFARE_Write() success: "));block = 5;//Serial.println(F("Authenticating using key A..."));status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, &key, &(mfrc522.uid));if (status != MFRC522::STATUS_OK) {Serial.print(F("PCD_Authenticate() failed: "));Serial.println(mfrc522.GetStatusCodeName(status));return;}// Write blockstatus = mfrc522.MIFARE_Write(block, &buffer, 16);if (status != MFRC522::STATUS_OK) {Serial.print(F("MIFARE_Write() failed: "));Serial.println(mfrc522.GetStatusCodeName(status));return;}else Serial.println(F("MIFARE_Write() success: "));Serial.println(" ");mfrc522.PICC_HaltA(); // Halt PICCmfrc522.PCD_StopCrypto1(); // Stop encryption on PCD}

author: SiliconWizard
author_rank: Super Contributor
timestamp: September 04, 2018, 02:53:51 pm
content: You're using a third-party library so we can't comment on this one.As for your code, I'm not sure what you mean by "I can only record 30 characters".I'm guessing the 30 said bytes would correspond to this call:Code:len = Serial.readBytesUntil('#', (char *) buffer, 30) ; // read family name from serialAfter this, what happens exactly?

author: JustMeHere
author_rank: Frequent Contributor
timestamp: September 06, 2018, 01:46:47 am
content: Please see the memory layout here:https://www.nxp.com/docs/en/data-sheet/MF1S50YYX_V1.pdfEach sector has 64 bytes, but 16 are used for control. It's been a few years since I messed with this, but this is where I would start.If you speak Spanish, the original lib you are using was written with many Spanish comments.