However, for a different idea, I needed the SPI interface to be available completely, and that meant that I must somehow change the implementation for the NFC module. One option is to use I2C as an interface and to adapt the hardware and the software to use it instead.
The ITEAD PN532 NFC Module, has only the SPI pins connected at the RaspberryPi connector. I believe this is some compromise that the guys at ITEAD must have did. However, the PN532 supports SPI, I2C and Serial, and all these interfaces can be accessed through the other connector, having in mind that they share the same pins.
In order to achieve I2C communication with a RaspberryPi, the following steps need to be made:
1. Change the switches on the NFC module to indicate that I2C will be used: SET0 set to H and SET1 set to L.
2. The I2C pins need to be rewired manually to the I2C pins of the RaspberryPi connector. My gruesome workaround is this:
3. The SPI pins of the RaspberryPi connector are still conected to the same shared pins, and with the rewiring, the I2C and SPI are interconnected and they won’t be functioning properly. To avoid this, the SPI pins need to be removed. Again, my workaround by cutting the 5 pins from the connector:
As of now, the device is ready to work with I2C. In order to test it, you can use the libnfc as described in this ITEAD studio blogpost. (see from number 8 onward).
The final step was to make all this functioning with Java code. For that, I extended my library by porting the elechouse PN532 implementation for I2C to Java with pi4j. After some struggle with the proper API usage, the implementation got quite clean. It is already added in the same project at GitHub.
As of this point, since I got everything working, my idea is to resume with this projec, port the whole PN532 implementation to Java, and making the API more clear to use. That I will cover in a future blog post.