help for interfacing RFID reader with atmega16

Status
Not open for further replies.

KruthikaMithra

Newbie level 4
Joined
Mar 24, 2013
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,332
i am trying to interface RFID reader with atmega16. The RFID reader i am using is **broken link removed** - baud rate 9600 & i am using ttl output from Tx pin. i hv used a 12Mhz oscillator on development board.
i am using the following code in eclipse. when the card is read i am getting some garbage characters like pi, delta, box or so.. plz help me get the correct tag id on lcd..

#include <avr/io.h>
#include <util/delay.h>
#include "lcd_lib.h"

#define F_CPU 12000000UL
#define USART_BAUDRATE 9600
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE *16UL)))- 1)

int main (void)
{
LCDinit();
LCDclr();
_delay_ms(50);
char ReceivedByte;

UCSRB |= (1 << RXEN) | (1 << TXEN);
//enable transmission and reception
UCSRC |= (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1); //Use 8-bit character size

UBRRH = (BAUD_PRESCALE >> 8);
// Load upper 8-bits of the baud rate value
UBRRL = BAUD_PRESCALE;
// Load lower 8-bits of the baud rate value

LCDGotoXY(1,0);

for (; // Loop forever
{

while ((UCSRA & (1 << RXC)) == 0) {};
// Do nothing until data have been received

ReceivedByte = UDR;
// Fetch the received byte value

LCDdisplay(ReceivedByte);
_delay_ms(300);
}
}
 
Last edited:

Check Step by Step..
First of all check whether your controller is working sending data and receiving data on Hyperterminal, you have to use level converter max232 for that.
And before directly interfacing the RFID with micro-controller, first check whether it is working or not.
Again check it with Hyper-Terminal and then interface it with Micro-Controller

- - - Updated - - -

I dont know the output of RFID,

from this

Code C - [expand]
1
2
3
4
ReceivedByte = UDR;
// Fetch the received byte value
 
LCDdisplay(ReceivedByte);



it looks that you displaying data directly on LCD.
you have to first convert it into ASCII to display it on lcd.

Suppose you get 1 from serial port.
Then you can't display 1 directly you have to convert 1 into ASCII this is done by ORing 1 with 0x30.
 

See this for AVR USART communication. Last Page. [/url]http://deans-avr-tutorials.googlecode.com/svn/trunk/InterruptUSART/Output/InterruptUSART.pdf[/url]

If you are getting some garbage then it means communication is happening and problem might be the data is inverted or baudrate is not matching.

You can directly connect your RFID with MCU as it gives TTL level communication pins.

If you have a datasheet of the RFID then post it. If it doesnt give ASCII data then you have to convert it to ascii using usart_read = usart_read + 0x30 before sending it to LCD. What is the default baudrate of the RFID reader? You have to use that baudrate for Serial Communication.

What I see is there is no Serial Interrupt code. I don't use AVR so I don't know much about it but try the code in the pdf and if you don't get the proper data on LCD then add 0x30 to the received data. If you don't use interrupt you will miss some data.

Try this project.

Enter 03312013 for 1st and 2nd .rar files and 0331201303312013 for the 3rd .rar file Simulation.
 

Attachments

  • atmega16_usart.rar
    54.7 KB · Views: 96
  • avr_usart.jpg
    297.8 KB · Views: 119
  • atmega16_rfid.rar
    103.9 KB · Views: 95
  • rdid_w.jpg
    331.2 KB · Views: 127
  • AVR RFID v2.rar
    107.7 KB · Views: 102
Last edited:

i tried the code.. but did'n get the output.. i checked & found out that my ISR is being called only 5 times.. my card contains number 133,35428 & if i try to display the read content after 5 ISR calls i'm getting the output 1335C. plz help me..
 

First i tried the first program and i got the output as "ppppp"
When i tried the second program i got the output as "1335C"
 

Attachments

  • 1.pdf
    158.1 KB · Views: 108
  • 2.pdf
    158.5 KB · Views: 131
Last edited:

zip and post your project files. Don't use delay in interrupt. Interrupts has more priority than other codes and if one interrupt is being serviced and there is a delay code in the interrupt routine then it will also have high priority and so if another interrupt occurs at that time then you will lose data. Did you try with my code? Can you post your RFID modules datasheet?

i==4 is wrong. It should be equal to length of data. If your RFID tag length is 8 then it should be (i==8). LCDdisplay(value) is wrong because you are not terminating the array with null character '\0' to make it a string. LCDdisplay() takes string as argument.


To confirm your RFID tag connect your RFID to PC USART using the Controller board that comes with the RFID board and then swipe your card and see what data you get in the hyperterminal.

I have a code for PIC like lcd_string(*str++); In that str is incremented first and so it prints from the 2nd character of the string. I don't know why that happens. It has to first print *str and then increment str. Maybe value[i++] is also behaving like that. Try to debug the code ans see.

Try the codes I have attached.
 

Attachments

  • usart1.txt
    1.2 KB · Views: 70
  • usart2.txt
    1.2 KB · Views: 77
Last edited:

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…