• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Capturing RFID Tag using Interrupt

Status
Not open for further replies.

Zaeed

New Member
PIC: PIC C18F4520
Compiler: HiTec C18
Programmer: Microchip MPLAB ICD2


Hey, i'm really new to PIC's etc so if i make stupid mistakes please forgive me.
I'm building a RFID scanning system using a ID-12 Reader. When a RFID is scanned, it is read through the USART Rx pin, where it is picked up by an interrupt.

Code:
#pragma interrupt_level 0
static void interrupt isr(void)
{
	if((RCIE)&&(RCIF))	
	{
		while(PROCESSING);
		DATA=RCREG;
		GET_DATA=1;				
	}
}
My main method loops waiting for GET_DATA to go high. When it does it launches the following code.

Code:
		if(GET_DATA)
		{
			PROCESSING = 1;
			if(DATA == 02) {
				received = 1;
				i=0;
			}
			else
			{
				if(DATA != 02)
				{
					inputString[i]= DATA;
					Led1=!Led1;
					i++;
				}
			}
			GET_DATA = 0;
			PROCESSING = 0;

		}
My issue is that when the array inputString[] is outputted to hyper terminal, I receive no tag. However, If i remove all the checks etc, and leave a bare bones code such as
Code:
if(GET_DATA)
inputString[i]=DATA;
i++;
inputString[] gets the full RFID Tag.

Can someone help me figure out whats wrong please?
 

Pommie

Well-Known Member
Most Helpful Member
If a character arrives whilst you are processing the previous character, PROCESSING will be 1 and you interrupt will wait forever.

Mike.
 

Zaeed

New Member
So would you suggest I simply dump the RFID into an array, and then process it after the whole RFID has been received? Or is there a better way to do it?
 

Pommie

Well-Known Member
Most Helpful Member
I would drop the processing variable and copy the data to a new variable,

Code:
	if(GET_DATA)
	{
		Temp=DATA;
		GET_DATA=0;
	.....
If you want to check for overrun then test GET_DATA for being set in the interrupt.

Mike.
 

Zaeed

New Member
Um, unless i'm missing something, how does setting DATA = RCREG; then Temp = DATA; help me at all?
 

Pommie

Well-Known Member
Most Helpful Member
Um, unless i'm missing something, how does setting DATA = RCREG; then Temp = DATA; help me at all?
It means that if another byte is received before you finish processing the previous byte, DATA doesn't get over written. The temporary variable effectively buffers an extra byte.

Mike.
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top