Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: PN532_MK20 USBDevice mbed
Fork of NFC_HTM_READ by
UtilidadesNFC.cpp
00001 /* 00002 -------------------------------------------------------------- 00003 ---- DECLARACIONES DE LIBRERIAS 00004 -------------------------------------------------------------- 00005 */ 00006 #include "mbed.h" 00007 #include "PN532_SPI.h" 00008 #include "NfcAdapter.h" 00009 #include "PN532.h" 00010 #include "USBSerial.h" 00011 #include "UtilidadesNFC.h" 00012 00013 /* 00014 -------------------------------------------------------------- 00015 ---- DECLARACIONES DE EXTERNAS 00016 -------------------------------------------------------------- 00017 */ 00018 extern USBSerial usb; 00019 extern DigitalOut red; 00020 extern DigitalOut green; 00021 extern DigitalOut blue; 00022 00023 /* 00024 -------------------------------------------------------------- 00025 ---- FUNCIONES 00026 -------------------------------------------------------------- 00027 */ 00028 00029 //Funcion para Inicializar el Chip NFC PN532 00030 NfcAdapter inicializarlector() 00031 { 00032 //Se inicializa el modulo de comunicacion SPI en los pines D11 (MOSI), D12 (MISO) y D13(CLK) 00033 SPI spi(D11, D12, D13); 00034 //se selecciona el pin SS (slave selector) 00035 PN532_SPI pn532spi(spi, D10); 00036 //envia comandos para inicializar comunicacion con el chip 00037 NfcAdapter nfc(pn532spi); 00038 //configura el chip en modo lectura escritura 00039 nfc.begin(); 00040 return nfc; 00041 }; 00042 00043 00044 //Funcion para identificar si hay un TAG en el modulo, obtener su ID y leer mensajes en memoria 00045 int LeerTagNFC(){ 00046 00047 //FUNCION PARA CONFIGURAR EL MODULO NFC 00048 NfcAdapter nfc = inicializarlector(); 00049 00050 while (1) { 00051 00052 usb.printf("\r buscando Tag NFC\n\r"); 00053 00054 00055 if (nfc.tagPresent()) { //ESCANEA HASTA ENCONTRAR UN TAG 00056 usb.printf("\r Tag encontrado \n\r"); 00057 unsigned int type1 = nfc.guessTagType(); //OBTIENE EL TIPO DE TAG 00058 NfcTag tag = nfc.read(); //LEE EL TAG 00059 if (type1 == TAG_TYPE_MIFARE_CLASSIC){ 00060 red = 0; 00061 blue = 0; 00062 wait(0.5); 00063 } 00064 00065 string id = tag.getUidString(); //OBTIENE EL ID DEL TAG 00066 00067 usb.printf("|id: %s|\n\r", id); 00068 00069 if (tag.hasNdefMessage()) { //INDICA SI EL TAG TIENE UN MENSAJE EN SU MEMORIA 00070 NdefMessage mensaje = tag.getNdefMessage();//OBTIENE EL MENSAJE DENTRO DEL TAG 00071 usb.printf("|Mensaje: %s|\n\r", mensaje); 00072 } 00073 return 1; 00074 } 00075 wait(1); 00076 } 00077 }
Generated on Tue Jul 12 2022 14:13:58 by
1.7.2
