Arduino NFC PN532 library error -


i using nfc shield http://www.elecfreaks.com/wiki/index.php?title=rfid_/_nfc_shield , using provided library not able run examples.
example code.

#include <pn532.h>  #define sck 13 #define mosi 11 #define ss 10 #define miso 12  pn532 nfc(sck, miso, mosi, ss);  void setup(void) { serial.begin(9600); serial.println("hello!");  nfc.begin();  uint32_t versiondata = nfc.getfirmwareversion(); if (! versiondata) {     serial.print("didn't find pn53x board");     while (1); // halt } // got ok data, print out! serial.print("found chip pn5"); serial.println((versiondata>>24) & 0xff, hex); serial.print("firmware ver. "); serial.print((versiondata>>16) & 0xff, dec); serial.print('.'); serial.println((versiondata>>8) & 0xff, dec); serial.print("supports "); serial.println(versiondata & 0xff, hex);  // configure board read rfid tags , cards nfc.samconfig(); }   void loop(void) { uint32_t id; // mifare type cards id = nfc.readpassivetargetid(pn532_mifare_iso14443a);  if (id != 0) {     serial.print("read card #"); serial.println(id); } } 

and gives error http://i.stack.imgur.com/mnvl9.jpg

and these detailed errors

    in file included readmifaretargetid.pde:1:     c:\users\saqib\documents\arduino\libraries\pn532_spi/pn532.h:44: error: expected `)' before 'cs' c:\users\saqib\documents\arduino\libraries\pn532_spi/pn532.h:48: error: 'boolean' not name type c:\users\saqib\documents\arduino\libraries\pn532_spi/pn532.h:49: error: 'uint32_t' not name type c:\users\saqib\documents\arduino\libraries\pn532_spi/pn532.h:50: error: 'uint32_t' not name type c:\users\saqib\documents\arduino\libraries\pn532_spi/pn532.h:51: error: 'uint32_t' not name type c:\users\saqib\documents\arduino\libraries\pn532_spi/pn532.h:57: error: 'uint32_t' not name type c:\users\saqib\documents\arduino\libraries\pn532_spi/pn532.h:58: error: 'uint32_t' not name type c:\users\saqib\documents\arduino\libraries\pn532_spi/pn532.h:60: error: 'boolean' not name type c:\users\saqib\documents\arduino\libraries\pn532_spi/pn532.h:65: error: 'uint8_t' not name type c:\users\saqib\documents\arduino\libraries\pn532_spi/pn532.h:67: error: 'boolean' not name type c:\users\saqib\documents\arduino\libraries\pn532_spi/pn532.h:68: error: 'uint8_t' not name type c:\users\saqib\documents\arduino\libraries\pn532_spi/pn532.h:69: error: 'uint8_t' has not been declared c:\users\saqib\documents\arduino\libraries\pn532_spi/pn532.h:69: error: 'uint8_t' has not been declared c:\users\saqib\documents\arduino\libraries\pn532_spi/pn532.h:70: error: 'uint8_t' has not been declared c:\users\saqib\documents\arduino\libraries\pn532_spi/pn532.h:70: error: 'uint8_t' has not been declared c:\users\saqib\documents\arduino\libraries\pn532_spi/pn532.h:71: error: 'uint8_t' has not been declared c:\users\saqib\documents\arduino\libraries\pn532_spi/pn532.h:72: error: 'uint8_t' not name type in file included c:\program files (x86)\arduino\hardware\arduino\cores\arduino/arduino.h:213,                  readmifaretargetid.pde:8: c:\program files (x86)\arduino\hardware\arduino\variants\mega/pins_arduino.h:35: error: expected unqualified-id before numeric constant c:\program files (x86)\arduino\hardware\arduino\variants\mega/pins_arduino.h:36: error: expected unqualified-id before numeric constant c:\program files (x86)\arduino\hardware\arduino\variants\mega/pins_arduino.h:37: error: expected unqualified-id before numeric constant c:\program files (x86)\arduino\hardware\arduino\variants\mega/pins_arduino.h:38: error: expected unqualified-id before numeric constant readmifaretargetid:8: error: no matching function call 'pn532::pn532(int, int, int, int)' c:\users\saqib\documents\arduino\libraries\pn532_spi/pn532.h:42: note: candidates are: pn532::pn532() c:\users\saqib\documents\arduino\libraries\pn532_spi/pn532.h:42: note:                 pn532::pn532(const pn532&) readmifaretargetid.pde: in function 'void setup()': readmifaretargetid:16: error: 'class pn532' has no member named 'getfirmwareversion' readmifaretargetid:28: error: 'class pn532' has no member named 'samconfig' readmifaretargetid.pde: in function 'void loop()': readmifaretargetid:35: error: 'class pn532' has no member named 'readpassivetargetid' 

this .h file library

 // pn532 library adafruit/ladyada // mit license  // authenticateblock, readmemoryblock, writememoryblock contributed // seeed technology inc (www.seeedstudio.com)   #include <arduino.h>  #define pn532_preamble 0x00 #define pn532_startcode1 0x00 #define pn532_startcode2 0xff #define pn532_postamble 0x00  #define pn532_hosttopn532 0xd4  #define pn532_firmwareversion 0x02 #define pn532_getgeneralstatus 0x04 #define pn532_samconfiguration  0x14 #define pn532_inlistpassivetarget 0x4a #define pn532_indataexchange 0x40 #define pn532_mifare_read 0x30 #define pn532_mifare_write 0xa0  #define pn532_auth_with_keya 0x60 #define pn532_auth_with_keyb 0x61   #define pn532_wakeup 0x55  #define  pn532_spi_statread 0x02 #define  pn532_spi_datawrite 0x01 #define  pn532_spi_dataread 0x03 #define  pn532_spi_ready 0x01  #define pn532_mifare_iso14443a 0x0  #define key_a   1 #define key_b   2   class pn532{ public:     pn532(uint8_t cs, uint8_t clk, uint8_t mosi, uint8_t miso);      void begin(void);      boolean samconfig(void);     uint32_t getfirmwareversion(void);     uint32_t readpassivetargetid(uint8_t cardbaudrate);     uint32_t authenticateblock( uint8_t cardnumber /*1 or 2*/,                 uint32_t cid /*card nuid*/,                 uint8_t blockaddress /*0 63*/,                 uint8_t authtype /*either key_a or key_b */,                 uint8_t * keys);      uint32_t readmemoryblock(uint8_t cardnumber /*1 or 2*/,uint8_t blockaddress /*0 63*/, uint8_t * block);     uint32_t writememoryblock(uint8_t cardnumber /*1 or 2*/,uint8_t blockaddress /*0 63*/, uint8_t * block);      boolean sendcommandcheckack(uint8_t *cmd, uint8_t cmdlen, uint16_t timeout = 1000);      //  private:     uint8_t _ss, _clk, _mosi, _miso;      boolean spi_readack();     uint8_t readspistatus(void);     void readspidata(uint8_t* buff, uint8_t n);     void spiwritecommand(uint8_t* cmd, uint8_t cmdlen);     void spiwrite(uint8_t c);     uint8_t spiread(void); }; 

and .cpp file

// pn532 library adafruit/ladyada // mit license  // authenticateblock, readmemoryblock, writememoryblock contributed // seeed technology inc (www.seeedstudio.com)  #include <arduino.h> #include "pn532.h"  //#define pn532debug 1  byte pn532ack[] = {0x00, 0x00, 0xff, 0x00, 0xff, 0x00}; byte pn532response_firmwarevers[] = {0x00, 0xff, 0x06, 0xfa, 0xd5, 0x03};  #define pn532_packbuffsiz 64 byte pn532_packetbuffer[pn532_packbuffsiz];  pn532::pn532(uint8_t clk, uint8_t miso, uint8_t mosi, uint8_t ss) {     _clk = clk;     _miso = miso;     _mosi = mosi;     _ss = ss;      pinmode(_ss, output);     pinmode(_clk, output);     pinmode(_mosi, output);     pinmode(_miso, input); }  void pn532::begin() {     digitalwrite(_ss, low);      delay(1000);      // not sure why have send dummy command synced     pn532_packetbuffer[0] = pn532_firmwareversion;     sendcommandcheckack(pn532_packetbuffer, 1);      // ignore response! }  uint32_t pn532::getfirmwareversion(void) {     uint32_t response;      pn532_packetbuffer[0] = pn532_firmwareversion;      if (! sendcommandcheckack(pn532_packetbuffer, 1))         return 0;      // read data packet     readspidata(pn532_packetbuffer, 12);     // check basic stuff     if (0 != strncmp((char *)pn532_packetbuffer, (char *)pn532response_firmwarevers, 6)) {         return 0;     }      response = pn532_packetbuffer[6];     response <<= 8;     response |= pn532_packetbuffer[7];     response <<= 8;     response |= pn532_packetbuffer[8];     response <<= 8;     response |= pn532_packetbuffer[9];      return response; }   // default timeout of 1 second boolean pn532::sendcommandcheckack(uint8_t *cmd, uint8_t cmdlen, uint16_t timeout) {     uint16_t timer = 0;      // write command     spiwritecommand(cmd, cmdlen);      // wait chip ready!     while (readspistatus() != pn532_spi_ready) {         if (timeout != 0) {             timer+=10;             if (timer > timeout)                 return false;         }         delay(10);     }      // read acknowledgement     if (!spi_readack()) {         return false;     }      timer = 0;     // wait chip ready!     while (readspistatus() != pn532_spi_ready) {         if (timeout != 0) {             timer+=10;             if (timer > timeout)                 return false;         }         delay(10);     }      return true; // ack'd command }  boolean pn532::samconfig(void) {     pn532_packetbuffer[0] = pn532_samconfiguration;     pn532_packetbuffer[1] = 0x01; // normal mode;     pn532_packetbuffer[2] = 0x14; // timeout 50ms * 20 = 1 second     pn532_packetbuffer[3] = 0x01; // use irq pin!      if (! sendcommandcheckack(pn532_packetbuffer, 4))         return false;      // read data packet     readspidata(pn532_packetbuffer, 8);      return  (pn532_packetbuffer[5] == 0x15); }  uint32_t pn532::authenticateblock(uint8_t cardnumber /*1 or 2*/,uint32_t cid /*card nuid*/, uint8_t blockaddress /*0 63*/,uint8_t authtype/*either key_a or key_b */, uint8_t * keys) {     pn532_packetbuffer[0] = pn532_indataexchange;     pn532_packetbuffer[1] = cardnumber;  // either card 1 or 2 (tested card 1)     if(authtype == key_a)     {         pn532_packetbuffer[2] = pn532_auth_with_keya;     }     else     {         pn532_packetbuffer[2] = pn532_auth_with_keyb;     }     pn532_packetbuffer[3] = blockaddress; //this address can 0-63 mifare 1k card      pn532_packetbuffer[4] = keys[0];     pn532_packetbuffer[5] = keys[1];     pn532_packetbuffer[6] = keys[2];     pn532_packetbuffer[7] = keys[3];     pn532_packetbuffer[8] = keys[4];     pn532_packetbuffer[9] = keys[5];      pn532_packetbuffer[10] = ((cid >> 24) & 0xff);     pn532_packetbuffer[11] = ((cid >> 16) & 0xff);     pn532_packetbuffer[12] = ((cid >> 8) & 0xff);     pn532_packetbuffer[13] = ((cid >> 0) & 0xff);      if (! sendcommandcheckack(pn532_packetbuffer, 14))         return false;      // read data packet     readspidata(pn532_packetbuffer, 2+6);  #ifdef pn532debug     for(int iter=0;iter<14;iter++)     {         serial.print(pn532_packetbuffer[iter], hex);         serial.print(" ");     }     serial.println();     // check basic stuff      serial.println("auth");     for(uint8_t i=0;i<2+6;i++)     {         serial.print(pn532_packetbuffer[i], hex); serial.println(" ");     } #endif      if((pn532_packetbuffer[6] == 0x41) && (pn532_packetbuffer[7] == 0x00))     {     return true;     }     else     {     return false;     }  }  uint32_t pn532::readmemoryblock(uint8_t cardnumber /*1 or 2*/,uint8_t blockaddress /*0 63*/, uint8_t * block) {     pn532_packetbuffer[0] = pn532_indataexchange;     pn532_packetbuffer[1] = cardnumber;  // either card 1 or 2 (tested card 1)     pn532_packetbuffer[2] = pn532_mifare_read;     pn532_packetbuffer[3] = blockaddress; //this address can 0-63 mifare 1k card      if (! sendcommandcheckack(pn532_packetbuffer, 4))         return false;      // read data packet     readspidata(pn532_packetbuffer, 18+6);     // check basic stuff #ifdef pn532debug     serial.println("read"); #endif     for(uint8_t i=8;i<18+6;i++)     {         block[i-8] = pn532_packetbuffer[i]; #ifdef pn532debug         serial.print(pn532_packetbuffer[i], hex); serial.print(" "); #endif     }     if((pn532_packetbuffer[6] == 0x41) && (pn532_packetbuffer[7] == 0x00))     {     return true; //read successful     }     else     {     return false;     }  }  //do not write sector trailer block unless know doing. uint32_t pn532::writememoryblock(uint8_t cardnumber /*1 or 2*/,uint8_t blockaddress /*0 63*/, uint8_t * block) {     pn532_packetbuffer[0] = pn532_indataexchange;     pn532_packetbuffer[1] = cardnumber;  // either card 1 or 2 (tested card 1)     pn532_packetbuffer[2] = pn532_mifare_write;     pn532_packetbuffer[3] = blockaddress;      for(uint8_t byte=0; byte <16; byte++)     {         pn532_packetbuffer[4+byte] = block[byte];     }      if (! sendcommandcheckack(pn532_packetbuffer, 20))         return false;     // read data packet     readspidata(pn532_packetbuffer, 2+6);  #ifdef pn532debug     // check basic stuff     serial.println("write");     for(uint8_t i=0;i<2+6;i++)     {         serial.print(pn532_packetbuffer[i], hex); serial.println(" ");     } #endif      if((pn532_packetbuffer[6] == 0x41) && (pn532_packetbuffer[7] == 0x00))     {     return true; //write successful     }     else     {     return false;     } }  uint32_t pn532::readpassivetargetid(uint8_t cardbaudrate) {     uint32_t cid;      pn532_packetbuffer[0] = pn532_inlistpassivetarget;     pn532_packetbuffer[1] = 1;  // max 1 cards @ once (we can set 2 later)     pn532_packetbuffer[2] = cardbaudrate;      if (! sendcommandcheckack(pn532_packetbuffer, 3))         return 0x0;  // no cards read      // read data packet     readspidata(pn532_packetbuffer, 20);     // check basic stuff      serial.print("found "); serial.print(pn532_packetbuffer[7], dec); serial.println(" tags");     if (pn532_packetbuffer[7] != 1)         return 0;      uint16_t sens_res = pn532_packetbuffer[9];     sens_res <<= 8;     sens_res |= pn532_packetbuffer[10];     serial.print("sens response: 0x");  serial.println(sens_res, hex);     serial.print("sel response: 0x");  serial.println(pn532_packetbuffer[11], hex);     cid = 0;     (uint8_t i=0; i< pn532_packetbuffer[12]; i++) {         cid <<= 8;         cid |= pn532_packetbuffer[13+i];         serial.print(" 0x"); serial.print(pn532_packetbuffer[13+i], hex);     }  #ifdef pn532debug     serial.println("targetid");     for(uint8_t i=0;i<20;i++)     {         serial.print(pn532_packetbuffer[i], hex); serial.println(" ");     } #endif       return cid; }   /************** high level spi */   boolean pn532::spi_readack() {     uint8_t ackbuff[6];      readspidata(ackbuff, 6);      return (0 == strncmp((char *)ackbuff, (char *)pn532ack, 6)); }  /************** mid level spi */  uint8_t pn532::readspistatus(void) {     digitalwrite(_ss, low);     delay(2);     spiwrite(pn532_spi_statread);     // read byte     uint8_t x = spiread();        digitalwrite(_ss, high);     return x; }  void pn532::readspidata(uint8_t* buff, uint8_t n) {     digitalwrite(_ss, low);     delay(2);     spiwrite(pn532_spi_dataread);  #ifdef pn532debug     serial.print("reading: "); #endif     (uint8_t i=0; i<n; i++) {         delay(1);         buff[i] = spiread(); #ifdef pn532debug         serial.print(" 0x");         serial.print(buff[i], hex); #endif     }  #ifdef pn532debug     serial.println(); #endif      digitalwrite(_ss, high); }  void pn532::spiwritecommand(uint8_t* cmd, uint8_t cmdlen) {     uint8_t checksum;      cmdlen++;  #ifdef pn532debug     serial.print("\nsending: "); #endif      digitalwrite(_ss, low);     delay(2);     // or whatever delay waking board     spiwrite(pn532_spi_datawrite);      checksum = pn532_preamble + pn532_preamble + pn532_startcode2;     spiwrite(pn532_preamble);     spiwrite(pn532_preamble);     spiwrite(pn532_startcode2);      spiwrite(cmdlen);     uint8_t cmdlen_1=~cmdlen + 1;     spiwrite(cmdlen_1);      spiwrite(pn532_hosttopn532);     checksum += pn532_hosttopn532;  #ifdef pn532debug     serial.print(" 0x"); serial.print(pn532_preamble, hex);     serial.print(" 0x"); serial.print(pn532_preamble, hex);     serial.print(" 0x"); serial.print(pn532_startcode2, hex);     serial.print(" 0x"); serial.print(cmdlen, hex);     serial.print(" 0x"); serial.print(cmdlen_1, hex);     serial.print(" 0x"); serial.print(pn532_hosttopn532, hex); #endif      (uint8_t i=0; i<cmdlen-1; i++) {         spiwrite(cmd[i]);         checksum += cmd[i]; #ifdef pn532debug         serial.print(" 0x"); serial.print(cmd[i], hex); #endif     }     uint8_t checksum_1=~checksum;     spiwrite(checksum_1);     spiwrite(pn532_postamble);     digitalwrite(_ss, high);  #ifdef pn532debug     serial.print(" 0x"); serial.print(checksum_1, hex);     serial.print(" 0x"); serial.print(pn532_postamble, hex);     serial.println(); #endif }  /************** low level spi */  void pn532::spiwrite(uint8_t c) {     int8_t i;     digitalwrite(_clk, high);      (i=0; i<8; i++) {         digitalwrite(_clk, low);         if (c & _bv(i)) {             digitalwrite(_mosi, high);         } else {             digitalwrite(_mosi, low);         }         digitalwrite(_clk, high);     } }  uint8_t pn532::spiread(void) {     int8_t i, x;     x = 0;     digitalwrite(_clk, high);      (i=0; i<8; i++) {         if (digitalread(_miso)) {             x |= _bv(i);         }         digitalwrite(_clk, low);         digitalwrite(_clk, high);     }     return x; } 

i beginner , appreciated.thanks

you're not including stdlib , stdbool headers give respectively uint8_t/uint32_t type , boolean type, please consider adding @ top of files:

#include <stdint.h> #include <stdbool.h> 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -