RFID interfacing with AVR microcontroller (ATmega16) using interrupts

This article covers how to extract and display the twelve byte unique tag ID received by RFID module on LCD using interrupt method. Before proceeding to this article readers must have knowledge of serial interrupt and LCD. In the previous article of RFID, polling method was used where the microcontroller was continuously monitoring the RXC flag. Keeping the microcontroller busy in monitoring the flag is not a good programming technique, so instead of polling method a programmer should prefer using interrupts.
RFID interfacing with AVR microcontroller (ATmega16) using interrupts

Since the output data of the RFID module uses RS232 protocol and is serial in nature, serial interrupt is used to receive the twelve byte unique ID.  Whenever an RFID tag comes in the proximity of the RFID reader module, the module transmits the twelve byte unique ID. Every time one byte of data is received, the controller is interrupted and the corresponding ISR gets executed, which stores the byte in a temporary variable and sends it to the LCD for display.
Since the length of the tag is twelve characters (and hence the serial interrupt will be generated twelve times one after the other) it must be noted that while defining ISR it should not be too long or consume more time. If ISR executes for a longer time then it may skip some data in case another interrupt is generated. In simple words the first ISR would not have executed completely and second ISR will be generated.  This would cause data loss.
RFID interfacing with AVR microcontroller (ATmega16) using interrupts schematic
The following is an ISR for the serial interrupt. When an interrupt is received, the variable get incremented and if the value of i is greater the 13, the incoming serial value will start writing from 0th position of second line. Since the unique id of the tag coming from RFID module is of twelve byte so, when the value of variable ‘i’ reaches 12 (i= 12) it means that one set of data is complete and the next coming value of data must be from next card.
value = UDR; // Put the received byte value into the variable “value”
LCD_write(value);   // write receive data to LCD

About The Author

Ibrar Ayyub

Ibrar Ayyub is an experienced technical writer with a Master's degree in computer science from BZU Multan University. He has written for various industries, mainly home automation, and engineering. He has a clear and simple writing style and is skilled in using infographics and diagrams. He is a great researcher and is able to present information in a well-organized and logical manner.

Follow Us:
Scroll to Top