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.
PN532.h
00001 #ifndef __PN532_H__ 00002 #define __PN532_H__ 00003 00004 #define PN532_PREAMBLE 0x00 00005 #define PN532_STARTCODE1 0x00 00006 #define PN532_STARTCODE2 0xFF 00007 #define PN532_POSTAMBLE 0x00 00008 00009 #define PN532_HOSTTOPN532 0xD4 00010 00011 #define PN532_FIRMWAREVERSION 0x02 00012 #define PN532_GETGENERALSTATUS 0x04 00013 #define PN532_SAMCONFIGURATION 0x14 00014 #define PN532_INLISTPASSIVETARGET 0x4A 00015 #define PN532_INDATAEXCHANGE 0x40 00016 #define PN532_INJUMPFORDEP 0x56 00017 #define PN532_TGINITASTARGET 0x8C 00018 #define PN532_TGGETDATA 0x86 00019 #define PN532_TGSETDATA 0x8E 00020 00021 00022 00023 #define PN532_WAKEUP 0x55 00024 #define PN532_SPI_STATREAD 0x02 00025 #define PN532_SPI_DATAWRITE 0x01 00026 #define PN532_SPI_DATAREAD 0x03 00027 #define PN532_SPI_READY 0x01 00028 00029 #define PN532_MIFARE_ISO14443A 0x0 00030 00031 #define KEY_A 1 00032 #define KEY_B 2 00033 00034 #define mosi1 p5 00035 #define miso1 p6 00036 #define sclk1 p7 00037 #define ss1 p8 00038 00039 #define REVERSE_BITS_ORDER(b) b = (b & 0xF0) >> 4 | (b & 0x0F) << 4; \ 00040 b = (b & 0xCC) >> 2 | (b & 0x33) << 2; \ 00041 b = (b & 0xAA) >> 1 | (b & 0x55) << 1 00042 00043 class PN532 00044 { 00045 public: 00046 00047 PN532(PinName mosi, PinName miso, PinName sclk, PinName ss); 00048 void begin(void); 00049 bool SAMConfig(void); 00050 uint32_t getFirmwareVersion(void); 00051 uint32_t configurePeerAsInitiator(void); 00052 uint32_t configurePeerAsTarget(void); 00053 bool initiatorTxRx(char* dataOut, char* dataIn); 00054 uint32_t targetTxRx(char* dataOut, char* dataIn); 00055 bool sendCommandCheckAck(uint8_t *cmd, uint8_t cmdlen, uint16_t timeout = 1000); 00056 00057 private: 00058 DigitalOut *_ss; 00059 SPI *_spi; 00060 00061 uint8_t read(uint8_t buff[], uint8_t n); 00062 uint8_t readSpiStatus(void); 00063 bool checkSpiAck(void); 00064 void writeCommand(uint8_t buf[], uint8_t len); 00065 void wakeup (void); 00066 inline void write(uint8_t data) { 00067 REVERSE_BITS_ORDER(data); 00068 _spi->write(data); 00069 } 00070 inline uint8_t read() { 00071 uint8_t data = _spi->write(0); 00072 REVERSE_BITS_ORDER(data); 00073 return data; 00074 } 00075 00076 00077 }; 00078 00079 #endif
Generated on Wed Jul 13 2022 10:41:14 by
1.7.2