#NFC PN532

<abstract>
Setting up a PN532 NFC module on a CM3-Panel using I2C
</abstract>

<img width="360px" src="https://public.stigok.com/img/1507824522111557533.jpg">


## Wirings 

| PANEL EXP1 | NFC MODULE |
|------------|------------|
| GND        | GND        |
| 3V3        | VCC        |
| I2C_SDA1   | SDA        |
| I2C_SCL1   | SCL        |

Set the dip switch o NFC module on teh I2C interface


<img src="./i2c.png" width="100px">

## Software installation

Enable I2C interface on the Pi with

	raspi-config

Install I2C utility binaries 

	sudo apt update
	sudo apt install i2c-tools

Probe for I2C devices:

	i2cdetect -y 1

	     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
	00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
	10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
	20: -- -- -- -- 24 -- -- -- -- -- -- -- -- -- -- -- 
	30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
	40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
	50: -- -- -- -- -- -- -- -- -- -- -- -- -- UU -- -- 
	60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
	70: -- -- -- -- -- -- -- --     

The NFC module is replying at the address 0x24

Install the NFC tools:

	sudo apt install libnfc5 libnfc-bin libnfc-examples
	
Configure the NFC tool editing this file:

	sudo nano /etc/nfc/libnfc.conf
	
and adding on it these two lines:

	device.name = "PN532 over I2C"
	device.connstring = "pn532_i2c:/dev/i2c-1"

List connected NFC readers:

	fc-scan-device -v

	nfc-scan-device uses libnfc 1.7.1
	1 NFC device(s) found:
	- pn532_i2c:/dev/i2c-1:
	    pn532_i2c:/dev/i2c-1
	chip: PN532 v1.6
	initator mode modulations: ISO/IEC 14443A (106 kbps), FeliCa (424 kbps, 212 kbps), ISO/IEC 14443-4B (106 kbps), Innovision Jewel (106 kbps), D.E.P. (424 kbps, 212 kbps, 106 kbps)
	target mode modulations: ISO/IEC 14443A (106 kbps), FeliCa (424 kbps, 212 kbps), D.E.P. (424 kbps, 212 kbps, 106 kbps)
	
Read a card or tag by first starting nfc-poll then physically holding a NFC/RFID tag or card 
in front of the reader:

	nfc-poll 
	
	nfc-poll uses libnfc 1.7.1
	NFC reader: pn532_i2c:/dev/i2c-1 opened
	NFC device will poll during 30000 ms (20 pollings of 300 ms for 5 modulations)
	ISO/IEC 14443A (106 kbps) target:
	    ATQA (SENS_RES): 00  04  
	       UID (NFCID1): 77  d3  d1  ad  
	      SAK (SEL_RES): 08  
	nfc_initiator_target_is_present: Target Released
	Waiting for card removing...done.

	
## Links 

* [PN532 NFC RFID Module User Guide](https://www.scribd.com/document/374277518/PN532-Manual-V3-pdf)
* [Setting up a PN532 NFC module on a Raspberry Pi using I2C](https://blog.stigok.com/2017/10/12/setting-up-a-pn532-nfc-module-on-a-raspberry-pi-using-i2c.html)
