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:
    16
    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:
    280
    Likes:
    29
    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:
    280
    Likes:
    29
    Location:
    Germany
    Try this out.
     
    • Agree Agree x 1
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. mahyar239

    mahyar239 New Member

    Joined:
    Oct 30, 2017
    Messages:
    16
    Likes:
    0

    could you please explain how the "timeout"works?
     
  6. wkrug

    wkrug Active Member

    Joined:
    May 30, 2010
    Messages:
    280
    Likes:
    29
    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.
     

Share This Page