/*LeerTodaMemoria * Se leeran sectores y bloques * */ //Revisado Prof: Bolaños 2018 - Ensayado #include #include #define RST_PIN 9 // Configurable, see typical pin layout above #define SS_PIN 10 // Configurable, see typical pin layout above MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance. MFRC522::MIFARE_Key key; /** * Initialize. */ int a; //variable para leer el sector int num;//variable para almacenar numero de bloque elegido void setup() { Serial.begin(9600); // Initialize serial communications with the PC while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4) SPI.begin(); // Init SPI bus mfrc522.PCD_Init(); // Init MFRC522 card // using FFFFFFFFFFFFh which is the default at chip delivery from the factory for (byte i = 0; i < 6; i++) { key.keyByte[i] = 0xFF; } Serial.println(F("******************************************")); Serial.println(F("******************************************")); Serial.println(F("Ingrese Tarjeta")); } /** * Main loop. */ //----------------------------------------- void(* resetFunc) (void) = 0; // esta es la funcion de reset //----------------------------------------- void loop() { // Look for new cards if ( ! mfrc522.PICC_IsNewCardPresent()) return; // Select one of the cards if ( ! mfrc522.PICC_ReadCardSerial()) return; //---Leo sector 0-------------- byte sector = 0; byte dataBlock[] = { 0x01, 0x02, 0x03, 0x04, // 1, 2, 3, 4, 0x05, 0x06, 0x07, 0x08, // 5, 6, 7, 8, 0x08, 0x09, 0xff, 0x0b, // 9, 10, 255, 12, 0x0c, 0x0d, 0x0e, 0x0f // 13, 14, 15, 16 }; MFRC522::StatusCode status; byte buffer[18]; byte size = sizeof(buffer); Serial.println(F("Datos actuales en el sector:")); mfrc522.PICC_DumpMifareClassicSectorToSerial(&(mfrc522.uid), &key, sector); Serial.println(); if (status != MFRC522::STATUS_OK) { Serial.print(F("MIFARE_Read() failed: ")); Serial.println(mfrc522.GetStatusCodeName(status)); } Serial.println(); //------Fin leer sector 0------------------ /* Ahora leemos desde el sector n */ //---------------leo el sector n----------- Serial.println("*********************************************************"); Serial.println("*********************************************************"); Serial.println("Indicar numero de sector (1 a 15) a leer y presione ENVIAR (2 seg):"); delay(2000); if (Serial.available()>0) { //A continuacion acciones realizadas solo desde PC-- //Delay para favorecer la lectura de caracteres delay(2000); //Se crea una variable que servirá como buffer String bufferString = ""; /* * Se le indica a Arduino que mientras haya datos * disponibles para ser leídos en el puerto serie * se mantenga concatenando los caracteres en la * variable bufferString */ while (Serial.available()>0) { bufferString += (char)Serial.read(); } num = bufferString.toInt(); //Serial.println(num); delay(2000); } a = num; delay(2000); if((a < 17)&& (a > 0)) { Serial.println(); Serial.println(); Serial.print("Ud parece que eligio bloque ---->"); Serial.println(a); Serial.println(); sector = a; //carga numero de sector a mostrar } else { Serial.println(); Serial.println("No es valido el dato o no se reconocio ninguno... espere... "); delay (2000); resetFunc(); // reseteo el Arduino } buffer[18]; size = sizeof(buffer); Serial.println(F("Datos actuales en el sector:")); mfrc522.PICC_DumpMifareClassicSectorToSerial(&(mfrc522.uid), &key, sector); Serial.println(); if (status != MFRC522::STATUS_OK) { Serial.print(F("MIFARE_Read() failed: ")); Serial.println(mfrc522.GetStatusCodeName(status)); } Serial.println(); //------------Fin lectura del sector n-------------- delay(50); Serial.println(F("Espere para colocar tarjeta.....")); Serial.println(F("******************************************")); Serial.println(F("******************************************")); //Reinicio luego de un tiempo delay(3000); resetFunc(); // reseteo el Arduino }