Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

RFID ID20 and atmega16

Status
Not open for further replies.

ANTI_HACKER

Member level 3
Member level 3
Joined
Sep 1, 2012
Messages
56
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,722
I am working on RFID ID-20 interfacing with atmega16. I have interfaced it with both PC hyperterminal and in Proteus simulation where the string was received by the atmega16 and displayed on the lcd.
The string received(on bith hyperterminal and atmega16) is "4500D8917D71" whereas the string on the tag(CARD) is " 11C10 0014193021 00216 37245"
Kindly tell me is it a valid string or not?
My second main problem is that when I connected it on hardware the lcd is showing some of the numbers, as were shown on PC, and the rest are garbage values.
My connection:
1 ------ GND
2 ------ 5V
3
4
5
6
7 ------ GND
8
9 ------ Atmega16 Rx(Pin 14)
10 ----- LED
11 ----- 5V



kindly help me through this..
 

Here's my code which is working perfect on simulation but gives some problems on hardware:

Code:
#include <mega16.h>
#include <delay.h>


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



#define rs PORTD.2 // defining rs pin to be PORTC.O
#define rw PORTD.3 //defining rs pin to be PORTC.1
#define en PORTD.4 //defining en pin to be PORCT.2

unsigned char data,message_no,;



unsigned char RFID[]="RFID TAG # is :";



 void init_USART(void)
{
    UCSRA = 0x00; //control register initialization
    UCSRB = 0x98; //enable transmitter and Rx   and rx interrupt
    UCSRC = 0x86; //async, no parity, 1 stop bit,
    
    UBRRL = BAUD_PRESCALE; // Load lower 8-bits of the baud rate value into the low byte of the UBRR register
    UBRRH = (BAUD_PRESCALE >> 8); // Load upper 8-bits of the baud rate value into the high byte of the UBRR register

}



void lcd_cmd(char ch) // a function used to send commands to lcd
{
    rs=0; //setting rs pin to zero (sending a command)
    rw=0; //setting rw pin to zero (to write to registers)
    PORTA=ch; // sending character on the port
    en=1; // setting enable pin
    delay_ms(2); //wait to make sure that the command is written successfully
    en=0; // clearing enable pin
}                 

void lcd_data(char ch) // a function used to send data to lcd
{
    count++;
    rs=1; //setting rs pin to one (sending data)
    rw=0; //setting rw pin to zero (to write to registers)

    PORTA = ch; // sending character on the port
    en=1; // setting enable pin
    delay_ms(2); //wait to make sure that the command is written successfully
    en=0; // clearing enable pin

}

void init_lcd() // a function to initialize LCD
{
 
        lcd_cmd(0x38); // configuring LCD for a two line display
        lcd_cmd(0x0E); //Turning Display and cursor ON
        lcd_cmd(0x01); //Clear Screen Display
        lcd_cmd(0x06); //Increment Cursor
        lcd_cmd(0x0C);   
}




void USART_Rx() 
{ 
    while((UCSRA & 0x80)==0x00); //wait for RXC flag       
    data = UDR;
}




void USART_Tx(char DATA) 
{ 
    while((UCSRA & 0x20)==0x00); //wait for UDRE flag
    UDR = DATA; //load data to UDR for transmission
     
}





interrupt[12] void USART_RX_INTERRUPT()
{
    data = UDR;
    lcd_data(data);
}




  
void main()
{

    DDRA=0XFF;
    
    
    init_lcd(); //initializing LCD 
    init_USART();
    
    #asm("SEI");
    
    
    i=0;
    while(RFID[i] != '\0')
    {
        lcd_data(RFID[i]);
        i++;
    }
    
    lcd_cmd(0xC0);
         
         
         /*
    while(1)
    {       
    
        USART_Rx();
        lcd_data(data);
        
    
    }
       */
       


       while(1); // Receiving by interrupts
    

}

Here's the datasheet:
https://www.sparkfun.com/datasheets/Sensors/ID-12-Datasheet.pdf
 
Last edited:

Ok I will check it and let you know what happens..
by the way why would I have to do that?

- - - Updated - - -

still giving the same problem :(
 

Interrupt should be serviced as soon as possible. If you have LCD code inside interrupt then it will also have delays (delays of LCD routines). The problem might be in your Hardware. Can you post your Schematic?
 
Last edited:

In your code seems to working with some LCD library but it is not included on the top of your program.

only appears
#include <mega16.h>
#include <delay.h>
 

@sabouras: i didnot get what are you saying? We dont need any library for LCD. Please clarify


@jayanth.devarayanadurga: I have removed the interrupts and made it simple like this :


Code:
void main()
{

    DDRA=0XFF;
    DDRD.2=1;
    DDRD.3=1;
    DDRD.4=1;
    init_lcd(); //initializing LCD 
    init_USART();

while(1)
    {
       
        USART_Rx();
        lcd_data(data);
    }
}




The hardware is a simple connection as given in my very first post.
You can check the hardware connections from the first post
 

No I am using Codevision avr as the complier
Here's the zip file (Ignore the extra functions that I made in the program):

- - - Updated - - -

I have seen the above links already.
I have done serial communication a lot on hardware.
I have designed my gps and gsm tracking system which involves a lot of serial comm.
but this time in rfid i am having problem :/

one other thing:
When I check the string from rfid on simulation I use '8' in the code as:
Code:
#define F_CPU 1000000
#define USART_BAUDRATE 9600
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 8))) - 1)


but when I go for hardware I have to make it '16' as:
Code:
#define F_CPU 1000000
#define USART_BAUDRATE 9600
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16))) - 1)



its ok right? because using '8' on code for hardware doesnot work at all. Moreover I had to do this in my previous tracking project aswell.
 

Attachments

  • RFID CODE.rar
    91.6 KB · Views: 67

Sorry i haven't seen your code. I believed that the problem was on lcd routine.
In the data sheet of the micro-controller http://www.atmel.com/Images/doc2466.pdf there is an example for the USART. Try it to see if something is going wrong with your hardware.
 

how can be there problem with lcd routine?? what should be done?
 

Check the speed of the USART in both sides (micro controller and the host). If there is not the same you may occur an overflow to uart buffer which may lead to reset or to stop the execution of the code. If you have a spare pin connect a led with a resistor and try to make it blink when you enter to USART communication rotuine.
 

Yes I have gone through the links
and the speeds are the same don know whats the problem with lcd
I have uploaded my code, simulation in complete file zipped above
the hardware is very very simple, just connections as described above
see the zip file and do something for me plz
 

have you measuring the voltage to see if you need voltage translator?
Have you connect the Rx from RS232 host to Tx of microcontroller?
Try to modify
void USART_Rx()
{
while ( !(UCSRA & (1<<RXC)) ) //wait for RXC flag
data = UDR;

}

Does the program goes into that routine?
Try something like that
lcd_data("Inside UART");
if data!=0 lcd_data("End UART here")
to see if it is stuck in the procedure or not.
 

oh yes i have done that..
its executing that function..
i checked that if its receiving the first HEX , up to middle.. its working fine..
On hardware i burn the program in which i defined the tag code and compared it with the one received and that work fine..
i mean the code was received and the same code define in the program was compared and ,upon successful matching i displayed on lcd 'welcome'
which was displayed which means the code is received correctly but the only problem is in the display of the tag code,, it simply does not display it completely
 

useful example
https://www.electronics-base.com/index.php/avr-tutorials/uart/95-avr-uart-single-character-example

- - - Updated - - -

if you like to receive a lot of bytes you must keep a history of the data and display them only if are the newer. Example
old_data=data;
data= uart_receive();
if (data!=old_data) {display_new_data}

- - - Updated - - -

the best of all is to receive the data into an interrupt base so be able when the receiving is done to make the proper checks. Also some characters from that you receive are not printable. You must convert them into hex that the LCD recognize.

- - - Updated - - -

The function for that is itoa
It needs
#include <stdlib.h>

http://www.nongnu.org/avr-libc/user-manual/group__avr__stdlib.html#ga4f6b3dd51c1f8519d5b8fce1dbf7a665

- - - Updated - - -

quick example
char str[5];
itoa(55, str, 10);
lcd_write(str);
 

Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top