RFID interfacing with atmega162 gives garbage on lcd

Discussion in 'Embedded Systems and Microcontrollers' started by naqirizvi, Jan 30, 2015.

  1. naqirizvi

    Thread Starter New Member

    Jan 30, 2015
    14
    0
    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.[​IMG]

    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 (Text):
    1. UCSR0C = 0b10000110;
    2. // Enable Tx and Rx, disable interrupts
    3. UCSR0B = 0b00011000;
    4.  
    5. // Normal speed, disable multi-proc
    6. UCSR0A = 0b00000000;
    7. // Baud rate 1200bps, assuming 1MHz clock
    8.  
    9.     UBRR0L = BAUD_PRESCALE;     // Load lower 8-bits of the baud rate value..
    10.                             // into the low byte of the UBRR register
    11.     UBRR0H = (BAUD_PRESCALE >> 8); // Load upper 8-bits of the baud rate value..
    12.                                   // into the high byte of the UBRR register
    I am getting data from RFID using
    Code (Text):
    1. while ((UCSR0A & (1 << RXC0)) == 0); // Do nothing until data have been received..
    2.                        // and is ready to be read from UDR
    3.  
    4.     return(UDR0); // return the byte
    Regards,
     
  2. sevenfold4

    Member

    Jan 12, 2015
    80
    7
    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.
     
  3. naqirizvi

    Thread Starter New Member

    Jan 30, 2015
    14
    0
    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.

     
  4. sevenfold4

    Member

    Jan 12, 2015
    80
    7
    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.
     
  5. naqirizvi

    Thread Starter New Member

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

     
  6. naqirizvi

    Thread Starter New Member

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

     
  7. sevenfold4

    Member

    Jan 12, 2015
    80
    7
    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?
     
  8. naqirizvi

    Thread Starter New Member

    Jan 30, 2015
    14
    0
    I forgot to mention that I have used this code in my program,
    Code (Text):
    1. #define F_CPU 12000000UL
    2. #define USART_BAUDRATE 9600
    3. #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);

     
  9. sevenfold4

    Member

    Jan 12, 2015
    80
    7
    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.
     
  10. naqirizvi

    Thread Starter New Member

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

     
  11. sevenfold4

    Member

    Jan 12, 2015
    80
    7
    What are you using to compile and program?
     
  12. naqirizvi

    Thread Starter New Member

    Jan 30, 2015
    14
    0
    AVR STUDIO 4,
    AVR-GCC
     
  13. naqirizvi

    Thread Starter New Member

    Jan 30, 2015
    14
    0
    below is the programmer isp 1.72 configuration that shows atmega162 fuses.
     
  14. sevenfold4

    Member

    Jan 12, 2015
    80
    7
    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.

    Edit
    Maybe this can help you
    http://www.avrfreaks.net/forum/set-external-crystal-oscillator
     
    Last edited: Jan 30, 2015
  15. naqirizvi

    Thread Starter New Member

    Jan 30, 2015
    14
    0
    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?

     
  16. sevenfold4

    Member

    Jan 12, 2015
    80
    7
    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.
     
  17. naqirizvi

    Thread Starter New Member

    Jan 30, 2015
    14
    0
    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. :)

     
  18. sevenfold4

    Member

    Jan 12, 2015
    80
    7
    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
     
    naqirizvi likes this.
  19. naqirizvi

    Thread Starter New Member

    Jan 30, 2015
    14
    0
    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
     
  20. naqirizvi

    Thread Starter New Member

    Jan 30, 2015
    14
    0
    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.

     
Loading...