125kHz RFID Reader Driver Technical Manual
Section 2. Adding The Driver To Your Project

2. Adding The Driver To Your Project

a) Notes About Our Source Code Files

There are many different ways to organise your source code and many different opinions on the best method! We have chosen the following as a very good approach that is widely used, well suited to both small and large projects and simple to follow.

Each .c source code file has a matching .h header file. All function and memory definitions are made in the header file. The .c source code file only contains functions. The header file is separated into distinct sections to make it easy to find things you are looking for. The function and data memory definition sections are split up to allow the defining of local (this source code file only) and global (all source code files that include this header file) functions and variables. To use a function or variable from another .c source code file simply include the .h header file.

Variable types BYTE, WORD, SIGNED_WORD, DWORD, SIGNED_DWORD are used to allow easy compatibility with other compilers. A WORD is 16 bits and a DWORD is 32 bits. Our projects include a ‘main.h’ global header file which is included in every .c source code file. This file contains the typedef statements mapping these variable types to the compiler specific types. You may prefer to use an alternative method in which case you should modify as required. Our main.h header file also includes project wide global defines.

This is much easier to see in use than to try and explain and a quick look through one of the included sample projects will show you by example.

Please also refer to the resources section of the embedded-code.com web site for additional documentation which may be useful to you.

b) Modifying Our Project Files

We may issue new versions of our source code files from time to time due to improved functionality, bug fixes, additional device / compiler support, etc. Where possible you should try not to modify our source codes files and instead call the driver functions from other files in your application. Where you need to alter the source code it is a good idea to consider marking areas you have changed with some form of comment marker so that if you need to use an upgraded driver file its as easy as possible to upgrade and still include all of the additions and changes that you have made.

c) Step By Step Instructions

Move The Main Driver Files To Your Project Directory

The following files are the main driver files which you need to copy to your main project directory:
rfid.c – The RFID driver functions
rfid.h

Move The Generic Global Defines File To Your Project Directory

The generic global file is located in the driver sample project directory. Copy the following file to your main project directory:

main.h – The embedded-code.com generic global file:

Check Driver Definitions

Check the definitions in the following file to see if any need to be adjusted for the microcontroller / processor you are using, and your hardware connections:-

rfid.h

Check the definitions in the following file and adjust if necessary for your compiler:-

main.h

Interrupts

In order to decode the modulated RFID tag data stream the driver requires the RFID Dout connection to be made to a microcontroller rising edge interrupt pin (see example circuit schematic). In your application initialisation you should configure the interrupt ready for operation but leave it disabled.

The driver reduces interrupt demands to an absolute minimum, with the interrupt occurring  at a maximum rate of once every 128uS when reading a valid RFID tag using the fastest bitrate option (most tags tend to use the slower and therefore longer range bitrate of 512uS).

In the interrupt handler you should provide code to determin the number of uS since the last rising edge interrupt (see rfid.h file for an example) and then call the rfid_sampling_rising_edge() function.

Timer

When reading of a tag is active every time a rising edge interrupt occurs the driver function that is called needs to be passed the time x1uS since the last rising edge interrupt occured. Therefore in your application initiialisation your should configure a suitable timer so that you can use it to obtain this time value.

You will need to provide some form of timer for the driver. Typically this can be done in your applications general heartbeat timer if you have one. Do the following every 1mS:-


	//----- RFID READER TIMER -----
	if (rfid_1ms_timer)
		rfid_1ms_timer--;

If you do not have a matching timer then using a time base that is slightly greater than 1mS is fine.

d) Application Requirements

In each .c file of your application that will use the driver functions include the ‘rfid.h’ file.

You will need to periodically call the drivers background processing function. Typically this can be done as part of your applications main loop. Add the following call:-


	//----- PROCESS RFID DRIVER -----
	rfid_process();