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.
ISR (USART_RXC_vect)
{
i++;
if(i==13)
{
i=1;
LCD_cmd(0xC0);
}
value = UDR; // Put the received byte value into the variable “value”
LCD_write(value);   // write receive data to LCD
}

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top