You are on page 1of 2

Elektor Electronics RFID Reader

(September 2006 issue, p. 26)

Programming the FT232R and LPC936 yourself

You don’t have to program the RFID reader, because we’ve already done that for you.
But you can if you want to, for instance if you want to make some changes to the
program. The EEPROM in the FTDI interface chip and the program memory in the
Philips 89LPC936 microcontroller can both be programmed via the USB interface.

If you want to program the FTDI chip, you will have to download the MProg program
from the FTDI website (http://www.ftdichip.com/Resources/Utilities.htm). Bear in mind
that this program will not run under Windows 98 or Windows ME, and that you must
install the D2XX drivers before running the program. These are not the same as the VCP
driver that you have probably already installed, which accesses the USB interface via a
simulated COM port. The easiest approach is to select the installation executable, which
installs both drivers at the same time.
Start MProg and select File/New. All functions will now be available. The meanings of
the various configuration options are explained in the MProg User Guide and the
FT232R data sheet. The circuit works well with all parameters set to the factory default
values.

To program the P89LPC936 microcontroller, you have to download Flash Magic from
http://www.esacademy.com/software/flashmagic/fmfree.htm. Start Flash Magic and
select the COM port connected to the USB interface (normally COM3). Set the baud rate
to 7200, Device to ‘89LPC936’, and Interface to ‘none’. If the RFID reader is connected
via a USB cable and both jumpers are fitted (which means the board is configured in
programming mode), you can first used ISP/Blank Check to test whether the interface is
working properly. Be careful with ISP/Device Configuration, because you can cause
everything to hang if you select the wrong clock rate, since the clock is also necessary
during programming. That means you should leave it set to ‘High frequency
crystal/resonator (4MHz-12MHz)’. There is another ‘hazardous’ setting, which is
Options/Advanced Options/Security. Ensure that ‘Protected ISP code’ is ticked (and
remains ticked). Aside from these parameters, you can experiment with everything.

It’s a good idea to enable ‘Erase blocks used by Hex file’ during programming so you
don’t have to manually delete the existing code before programming. You must remove
both jumpers to run the downloaded code after programming – otherwise the circuit will
just sit there doing nothing.

If for some reason you want to program a new LPC9xx from the factory, you should be
aware that the internal 7.373-MHz oscillator is used in the new chips. There is thus no
oscillator signal on pins 8 and 9. If you wish, you can use ISP/Device Configuration to
select a different oscillator. The baud rate setting of 7200 also works well with the
internal oscillator. However, the baud rate must be reduced (to 600 baud, for example) if
you select the 400-kHz watchdog . This value is not shown in the pull-down menu, but to
our surprise it turns out to be possible to simply type a value into the menu.

We must admit it took us a little while to figure this out…


(060132-1)

Table
Reader and card commands for Mifare UltraLite

Reader functions
void MFRc522Init(void);
int ReaderRfReset(unsigned int msec);
Card activation
int ISO14443_Request(unsigned char req_cmd, unsigned char *atq);
int ISO14443_Anticoll (unsigned char bcnt, unsigned char *snr);
int ISO14443_Select(unsigned char *snr, unsigned char *sak);
int ISO14443_HALTA(void);
Mifare UltraLight memory manipulation
int MifareRead(unsigned char addr, unsigned char *data);
int MifareULWrite(unsigned char addr, unsigned char *data);

Listing
Code for card activation and reading data blocks from a Mifare® UltraLite card. The data blocks
are output afterwards via the serial interface.

while(1)
{
status = ISO14443_Request(WUPA, &bATQ);
if(status != STATUS_SUCCESS)
continue;

status = ISO14443_Anticoll(Level1,0,&abSNR[0]);
if(status != STATUS_SUCCESS)
continue;

status = ISO14443_Select(Level1, &abSNR[0], &bSAK);


if(status != STATUS_SUCCESS)
continue;

// Check if UID is complete


if((bSAK & 0x04) == 0x04)
{
// UID not complete
status = ISO14443_Anticoll(Level2,0,&abSNR[4]);
if(status != STATUS_SUCCESS)
continue;

status = ISO14443_Select(Level2, &abSNR[4], &bSAK);


if(status != STATUS_SUCCESS)
continue;
}

// Read UltraLight Block 0..3


status = Read(0,abDataBuffer);

You might also like