1. 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.
    Dismiss Notice

How to read RFID tag by ATmega32 using Codevision ?

Discussion in 'AVR' started by mahyar239, Oct 30, 2017.

Tags:
  1. mahyar239

    mahyar239 New Member

    Joined:
    Oct 30, 2017
    Messages:
    20
    Likes:
    0
    should I put the first part of the code in interrupt routine?
    sth like the following code?
    // USART0 Receiver interrupt service routine
    interrupt [USART0_RXC] void usart0_rx_isr(void)
    {
    char status,data;
    status=UCSR0A;
    data=UDR0;
    if ((status & (FRAMING_ERROR | PARITY_ERROR | DATA_OVERRUN))==0)
    {
    rx_buffer0[rx_wr_index0]=data;
    if (++rx_wr_index0 == RX_BUFFER_SIZE0) rx_wr_index0=0;
    if (++rx_counter0 == RX_BUFFER_SIZE0)
    {
    rx_counter0=0;
    rx_buffer_overflow0=1;
    };
    };
    }
     
    Last edited: Nov 7, 2017
  2. wkrug

    wkrug Active Member

    Joined:
    May 30, 2010
    Messages:
    298
    Likes:
    31
    Location:
    Germany
    The first part ( Interrupt Routine ) would be generated by the Automatic Programm Generator.
    Let it like it is.

    Your parameter is the rx_counter.
    You should test this variable in main while(1) loop.
    When > 0 a new Byte arrived and You have to do some action -> Readout and process.

    E.G. When put in an LCD Output routine into Interrupt, the whole controller is blocked until the output is done.

    I'm not shure that You know how it works.

    The RX Interrupt get any Byte that was received via USART and save it in a Ring Buffer.

    Your Job ist to readout this Buffer, evaluate the data and generate "C" compatible strings.
    There are many possible way's to do this.
     
    • Agree Agree x 1
  3. wkrug

    wkrug Active Member

    Joined:
    May 30, 2010
    Messages:
    298
    Likes:
    31
    Location:
    Germany
    Try this out.
     
    • Agree Agree x 1
  4. dave miyares

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    2
    Likes:
    -10
  5. mahyar239

    mahyar239 New Member

    Joined:
    Oct 30, 2017
    Messages:
    20
    Likes:
    0
    could you please explain how the "timeout"works?
     
  6. wkrug

    wkrug Active Member

    Joined:
    May 30, 2010
    Messages:
    298
    Likes:
    31
    Location:
    Germany
    Every Timer0 Overflow would called the
    interrupt [TIM0_OVF] void timer0_ovf_isr(void)
    routine.
    In this routine the uc_timeout variable would be incremented by 1.

    In this section
    if(uc_timeout>OVERFLOWTIME) //Timeout overflown ?
    {
    uc_timeout=0; //Yes! Reset Timeout
    datapoint=0; //Reset data pointer
    }
    }
    else //Else waiting for new tag
    {
    uc_timeout=0; //Reset Timeout
    }

    the uc_timeout variable would be testet with an overflow value - In this case 15, that give You ~0,5s timeout at 8MHz clock and the current setting of timer0.
    If the variable is bigger than this, the datapointer will be set to 0 and so all the saved Bytes will be thrown away.

    In the other case a new byte was received, the overflow since the last byte was not achieved and the timeout variable would be set to 0 until the next byte arrives.

    You could check this out with the simulator of AVR Studio 7.

    Codevision has no integrated simulator.
    The exchange File between this 2 solutions is the .cof File.
     
  7. mahyar239

    mahyar239 New Member

    Joined:
    Oct 30, 2017
    Messages:
    20
    Likes:
    0
    Hello, I'm here again..finally I made the code for showing rfid tag's number on lcd but I don't know how to compare it with a given number
     
  8. dave miyares

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    2
    Likes:
    -10
  9. mahyar239

    mahyar239 New Member

    Joined:
    Oct 30, 2017
    Messages:
    20
    Likes:
    0
    I got the tag number by gets(code,11) and when i'm trying to show it on LCD one extra character appears on (0,0) on the LCD, how can cut the desired number (just the digits written on the tag?
     
  10. wkrug

    wkrug Active Member

    Joined:
    May 30, 2010
    Messages:
    298
    Likes:
    31
    Location:
    Germany
    I would suggest You to insert a learn routine into the Controller.
    You'll bring the controller into a "learn mode" by pressing a Button or else method.
    Then hold the new card on the reader.
    The Controller read the string and store it into an EEPROM place, to make it save at power down.

    In normal Mode the entire card code will be compared with the stored one's.

    Old Cards can be removed manually, when defect manually by an own routine.
    The Codes behind this card should be sortet new, to use the EEPROM space effective.
     
  11. mahyar239

    mahyar239 New Member

    Joined:
    Oct 30, 2017
    Messages:
    20
    Likes:
    0
    let me explain my problem clearly
     
  12. mahyar239

    mahyar239 New Member

    Joined:
    Oct 30, 2017
    Messages:
    20
    Likes:
    0
    the 10 digits are my numbers but the first character is extra and I don't know what it is, tried to delete it but didn't work upload_2017-12-25_20-32-8.png upload_2017-12-25_20-32-8.png
     
  13. wkrug

    wkrug Active Member

    Joined:
    May 30, 2010
    Messages:
    298
    Likes:
    31
    Location:
    Germany
    I think the fail ist a wrong setting of the Jumper 2 and 3 of the RF01D.
    When SW 3 set to 1 the RF01D send a start Byte ( 0x02 ).
    The Display interpret's that as character and display this.
    Set this pin to 0 should solve that problem.

    You also can eliminate that by change the first character into an other byte of ASCII code e.g. 0x20 for a space.

    Or copy the String into an other without the first byte.
    The length of a string You can get with the command strlen.
    So copy the String from byte 1 to the end to byte 0 to an another string.

    You see many way's to solve that.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice