RFID interfacing with atmega162 gives garbage on lcd

Thread Starter

naqirizvi

Joined Jan 30, 2015
14
Hi,
I have interfaced RFID and atmega162 as in picture , but I am getting garbage with blank spaces, hypens on lcd , please see my code and tell me whats could be the problem, Hoping for your help.
Please have a look on schematic and also coding for USART. What could be the problem that Y i getting garbagr on my lcd.


Coding I used for USART for getting input from rfid and displaying on LCD, all other lcd functions are not included in code below.

I initialized my uart using the code below I got it on internet.
Code:
UCSR0C = 0b10000110;
// Enable Tx and Rx, disable interrupts
UCSR0B = 0b00011000;

// Normal speed, disable multi-proc
UCSR0A = 0b00000000;
// Baud rate 1200bps, assuming 1MHz clock

    UBRR0L = BAUD_PRESCALE;     // Load lower 8-bits of the baud rate value..
                            // into the low byte of the UBRR register
    UBRR0H = (BAUD_PRESCALE >> 8); // Load upper 8-bits of the baud rate value..
                                  // into the high byte of the UBRR register
I am getting data from RFID using
Code:
while ((UCSR0A & (1 << RXC0)) == 0); // Do nothing until data have been received..
                       // and is ready to be read from UDR

    return(UDR0); // return the byte
Regards,
 

sevenfold4

Joined Jan 12, 2015
80
Have you double checked your baud rate?
Easiest way to check baud rate is to connect it to a computer and use terminal.
Also did you test your LCD?
When wrongly initialized they will produce corrupted data.
 

Thread Starter

naqirizvi

Joined Jan 30, 2015
14
Thank 4 ur reply,
I connected my RFID with PC and set 9600 baud on pc , I was getting 12 charachters on Pc , i think those were rfid tags,

I am printing "Hello World" on LCD and thats working perfectly.

Have you double checked your baud rate?
Easiest way to check baud rate is to connect it to a computer and use terminal.
Also did you test your LCD?
When wrongly initialized they will produce corrupted data.
 

sevenfold4

Joined Jan 12, 2015
80
Thank 4 ur reply,
I connected my RFID with PC and set 9600 baud on pc , I was getting 12 charachters on Pc , i think those were rfid tags,

I am printing "Hello World" on LCD and thats working perfectly.
What about PC and MCU? Just to check if the baud rate you set on the MCU is actually the one you want.
When i was setting my UART up i got some trashy characters, because the baud rate did not match.
 

Thread Starter

naqirizvi

Joined Jan 30, 2015
14
How Can I verify it with PC and AVR.
I have realterm. A USB cable with Tx and Rx.
and ATMEGA162.

What about PC and MCU? Just to check if the baud rate you set on the MCU is actually the one you want.
When i was setting my UART up i got some trashy characters, because the baud rate did not match.
 

Thread Starter

naqirizvi

Joined Jan 30, 2015
14
How Can I verify it with PC and AVR.
I have realterm. A USB cable with Tx and Rx.
and ATMEGA162.

What about PC and MCU? Just to check if the baud rate you set on the MCU is actually the one you want.
When i was setting my UART up i got some trashy characters, because the baud rate did not match.
 

sevenfold4

Joined Jan 12, 2015
80
Well it should be just that simple. Connect>scan ports in real term, match the baud rate and click Change.
Oh, do you only have the chip? You don't have some prototyping board?
 

Thread Starter

naqirizvi

Joined Jan 30, 2015
14
I forgot to mention that I have used this code in my program,
Code:
#define F_CPU 12000000UL
#define USART_BAUDRATE 9600
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)
Could the problem is because of crystal or fuses?

I am getting 1.25 sec beep on _delay_ms(100);

Well it should be just that simple. Connect>scan ports in real term, match the baud rate and click Change.
Oh, do you only have the chip? You don't have some prototyping board?
 

sevenfold4

Joined Jan 12, 2015
80
The frequency you have there could be wrong, that is why i asked you to check it.
I remember back when i used MPlab i had to choose the Crystal, else it would use something else.
 

Thread Starter

naqirizvi

Joined Jan 30, 2015
14
So How could I select External crystal.
Do i need to change fuses? Or just in programming?

The frequency you have there could be wrong, that is why i asked you to check it.
I remember back when i used MPlab i had to choose the Crystal, else it would use something else.
 

Thread Starter

naqirizvi

Joined Jan 30, 2015
14
So how could I select external crystal?
Selecting external crystal will set baud rate and then I can get RFID tag on my screen? This is how it will work?

Yea, you have to make sure you are picking the external crystal manually, if you have not done it, else it will use the internal RC oscillator, and you will not be getting the baud rate you want. I'll edit my post when i find the option.
 

sevenfold4

Joined Jan 12, 2015
80
So how could I select external crystal?
Selecting external crystal will set baud rate and then I can get RFID tag on my screen? This is how it will work?
Check the link i gave you. Once you select the external crystal, you can test with the delay, does it seem right?
If your baud rate is off, it won't work, or it will be gibberish.
When i used PIC16F887 i had to use the required baud rate value to calculate a new value that i could use in the registry to set the baud rate.
 

Thread Starter

naqirizvi

Joined Jan 30, 2015
14
I have viewed this link before but it is left unanswered.
please go through this link,
http://treehouseprojects.ca/fusebits/
Could you prefer what fuses I should change for 12MHZ crystal.

I have 2 dead avr, because i changed some fuses on them and they goes wrong. :'(
That Y i need an expert to tell me what fuses to program. :)

Check the link i gave you. Once you select the external crystal, you can test with the delay, does it seem right?
If your baud rate is off, it won't work, or it will be gibberish.
When i used PIC16F887 i had to use the required baud rate value to calculate a new value that i could use in the registry to set the baud rate.
 

sevenfold4

Joined Jan 12, 2015
80
I have viewed this link before but it is left unanswered.
please go through this link,
http://treehouseprojects.ca/fusebits/
Could you prefer what fuses I should change for 12MHZ crystal.

I have 2 dead avr, because i changed some fuses on them and they goes wrong. :'(
That Y i need an expert to tell me what fuses to program. :)
This is where i stop then.
I would just follow the guide. I have never used this program the answers, about the clock source etc... i got from doing some quick reading.
I am 100% sure that later today, when the actual professionals log in your problem will get solved.

The guide you gave me is very detailed tho. If you follow it you will be okay.
I have to leave for a couple of hours myself.

Best of luck
 

Thread Starter

naqirizvi

Joined Jan 30, 2015
14
Ok, Well I set my fuse low value to FF problem was still there,
then I set it default now a new problem arise , I am getting beep without delay. nothing is displaying on LCD.
normally after a beep lcd shows "Welcome"
but now lcd has got boxes, and beep is continous
 

Thread Starter

naqirizvi

Joined Jan 30, 2015
14
Thanks Man , I finally got it working,
I go through datasheet. And set my lFuse=FF(for selecting external clock >8Mhz)
hfuse=99(default value) eFuse=ff(default value)
and also included
#define F_CPU 12000000UL

Now my controller is working on 12Mhz clock. Also reading my RFID tag and displaying on lcd.
But I am also getting garbage before and after tag. but I am able to get 100% correct tag.

If you know who could i remove garbage then tell me please.

This is where i stop then.
I would just follow the guide. I have never used this program the answers, about the clock source etc... i got from doing some quick reading.
I am 100% sure that later today, when the actual professionals log in your problem will get solved.

The guide you gave me is very detailed tho. If you follow it you will be okay.
I have to leave for a couple of hours myself.

Best of luck
 
Top