In an earlier post I detailed the basics of interfacing to the popular RC522 and PN532 RFID modules. I followed that up with a simple Electronic Wallet implementation also based on those two modules. All of those projects used my favorite combination of the PIC microcontroller and assembly language programming. Given my recent fascination with the Arduino (and a few rainy days) I decided to translate the PIC programs for the PN532. I won’t repeat the tons of useful information found in my previous posts so I highly recommend that you read them to better understand what is going on.
Step 1: Schematic
The schematic is shown above and includes the connections for a 4-bit 1602 LCD interface. It looks pretty much like the PIC diagram and uses the built-in serial interface of the Arduino. Note the two resistors connected to the PN532 module RXD input. Even though the module accepts +5 volts, the chip itself operates at +3.3 volts. The two resistors act as a voltage divider for the +5 volt signal coming from the Arduino serial TX pin. The Arduino is happy with the +3.3 volt serial data from the Arduino so no logic level conversion is required.
There are two switches used for the Electronic Wallet version but they are not needed for the basic version of the software. One switch allows for manual initialization of the tag and the other allows for adding credits to the tag. The switches can be either momentary contact or toggle types and would normally be hidden from the user.
Step 2: Software
As in the PIC application there are two versions of software. One is a demo of the basic read/write capabilities of a tag and the other is an example of using a tag as an Electronic Wallet. For the most part they are direct translations of the PIC assembly language. There are a few subtle differences in implementation but nothing that really changes the functionality.
The basic version uses an arbitrary data pattern that gets modified each loop through the code. The Electronic Wallet version has an initialized credit value of “0” and there are defined values at the front of the software for the amounts to increment or decrement the stored credits. Keep in mind that these values are in packed BCD format. That means that a value of “0x12” represents twelve.
Because everything is stored in packed BCD, the math for increment and decrement needs to include correction of the results. That operation is called “Decimal Adjust” and some microcontrollers include specific instructions for both DAA (Decimal Adjust Add) and DAS (Decimal Adjust Subtract). The PIC I used in the original implementation did not have that capability so I wrote a couple of macros to handle it. I needed to figure out equivalent pieces of software for the Arduino and found a DAA function online but not a DAS function.
That’s it for this post. Check out my other Instructables and also my website at: www.boomerrules.wordpress.com