i have a problem in using USART for my RFID project

Discussion in 'Embedded Systems and Microcontrollers' started by barde, May 12, 2009.

  1. barde

    Thread Starter New Member

    May 2, 2009
    2
    0
    Hi everyone,
    I am a beginner doing a project on RFID (radio frequency Identification). I am using a device, Parallax RFID Reader Module, to read the RFID transponder tags.

    Each transponder tag contains a unique identifier (one of 240, or 1,099,511,627,776, possible combinations) that is read by the RFID Reader Module and transmitted to the host via a simple serial interface. For my project the unique code will be transmitted by USART.

    When a valid RFID transponder tag is placed within range of the activated reader, the unique ID will be transmitted as a 12-byte ASCII string via the TTL-level SOUT (Serial Output) pin in the following format:

    MSB
    Start Byte Unique ID Unique ID Unique ID Unique ID Unique ID Unique ID Unique ID Unique ID Unique ID (0x0A) Digit 1 Digit 2 Digit 3 Digit 4 Digit 5 Digit 6 Digit 7 Digit 8 Digit 9



    LSB
    Unique ID Stop Byte
    Digit 10 (0x0D)







    The start byte and stop byte are used to easily identify that a correct string has been received from the reader (they correspond to a line feed and carriage return characters, respectively). The middle ten bytes are the actual tag's unique ID.


    All communication is 8 data bits, no parity, 1 stop bit, non-inverted, least significant bit first (8N1). The baud rate is configured for 2400bps, a standard communications speed supported by most any microprocessor or PC, and cannot be changed. The Parallax RFID Reader Module initiates all communication. The Parallax RFID Reader Module can connect directly to any TTL-compatible. The RFID reader will be interfaced to a microcontroller (PIC16F77A) and the unique code it detects from a transponder tag will be transmitted to the microcontroller by USART. The microcontroller then compares this unique code to a previously stored code. Then, it shows the name and id assigned to the tag on an LCD.

    So I wrote a program (to the MCU using MPLAB) that does this, but I encountered a problems after connecting the circuit when it came to comparing the unique code from the card to a previously stored code. I do not know if it is the MCU that is not receiving the correct code or I am not setting the USART correctly. Below are the programming parts that are involved in the steps I mentioned above.

    This is how I set up the USART
    //setup USART
    SPBRG = 129; //set baud rate to 2400 for 20Mhz
    BRGH = 0; //baud rate low speed option
    TXEN = 1; //enable transmision
    CREN = 1; //enable reception
    SPEN = 1; //enable serial port



    This is the stored code
    unsigned char id_2[10]={"0006642982"};


    This is the function that collects and returns the unique code from the RFID reader

    unsigned char uart_rec(void) //receive uart value
    {
    unsigned char rec_data;
    while(RCIF==0); //wait for data
    rec_data=RCREG;
    return rec_data; //return the data received
    }

    this assigns the unique code to a variable

    unsigned char data[10];
    for(i=0;i<10;i+=1)data=uart_rec(); //wait for 10 character data from the RFID reader



    This compares the unique and the stored code and puts it in a switch case

    //comparing with 2nd id
    temp=0;

    //comparing the receive id with the saved id
    for(i=1;i<10;i+=1) //if the id is different from the id defined above,
    { //then set temp=1
    if((data)!=(id_2))temp=1; //if temp=0 when id matched, set the database=1
    }
    if (temp==0) database =2; //if temp=0 when id matched, set the database=2


    switch(database) //switch case
    {
    case 2: //id mached
    beep();
    .
    .
    .
    .



    Am I doing something wrong? I will be very glad if someone can help me out.
     
Loading...