Shop OBEX P1 Docs P2 Docs Learn Events
RFID reader and PIC microcontroller — Parallax Forums

RFID reader and PIC microcontroller

astronovaastronova Posts: 2
edited 2008-09-10 06:52 in General Discussion
Hi all,

I am trying out a simple security system using RFID and a PIC microcontroller. The microcontroller I am using is a PIC16F877. I would like to know whether there r any problems if I connect the S/OUT pin of the RFID reader directly to the RC7 pin of the microcontroller. I read from www.cytron.com.my/topic.asp?tid=1747 that the S/OUT pin should be connected to a voltage level converter before connecting it to the PIC.

Is this correct? Currently, I am only able to read in the first 2 bytes of the unique ID of a RFID tag and I am suspecting that this might be causing the problem for me. If u need more info, I will gladly provide them cos I do not know what other info is required here.

Thanks for the help!

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-09-09 17:39
    They never read the documentation for the RFID reader. The Sout pin and the /Enable pin are both 5V logic and can be connected to a microcontroller I/O pin as long as the microcontroller is running at 5V or has 5V logic tolerant/compatible I/O pins. There's nothing different about the later bytes of the RFID compared to the first two bytes. There may be something wrong with your program. Check to make sure that the receiving code has the proper Baud timing.
  • astronovaastronova Posts: 2
    edited 2008-09-10 05:52
    Thanks for the reply.

    I determined that I have received an overrun error (OERR), which may explain why I am only able to receive the first two bytes. Could this be a problem of an incorrect baud timing?

    For the PIC16F877, I have set BRGH (high baud rate select pin) to 0. This should let the PIC operate in a low-speed asynchronous mode. According to the formula given in the datasheet: (Asynchronous) Baud Rate = FOSC/(64(X+1)). My FOSC is 20Mhz and I have set X=129. Thus, the given baud rate should be equal 2403bps. This is pretty close to the 2400bps rate stated in the RFID reader datasheet. Is there any misconception on my part?

    A part of code that does the above is shown:
    BRGH=0; // Fosc/(64(X+1))=2400bps
    SPBRG=129; // X=129

    SYNC=0; // USART Mode Select bit: Asynchronous mode
    SPEN=1; //Serial port enabled (RC7 takes input from SOUT)
    CREN=1; //Enables continuous receive

    My PIC datasheet can be found at this link. ww1.microchip.com/downloads/en/DeviceDoc/30292c.pdf
    Relevant pages are from pg95 to pg102.

    Thks in advance!
  • Mike GreenMike Green Posts: 23,101
    edited 2008-09-10 06:02
    I can't help you with the PIC programming. An overrun error generally means that your program did not service the UART before another character was received. It usually is not related to Baud timing unless that results in a character that's not recognized by your program, hence not going back to read another character.
  • Harrison.Harrison. Posts: 484
    edited 2008-09-10 06:05
    I believe the PIC16 series with a built in USART only have a 2 byte receive buffer. You'll need to make sure you pull out characters fast enough to prevent a buffer overrun.

    It looks like you're using C. Some C compilers (such as CCS C) have built in abstracted serial methods which are very helpful. You might try using those instead of fiddling with the calculations directly (hopefully your compiler supports that).

    Post Edited (Harrison.) : 9/10/2008 6:10:36 AM GMT
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2008-09-10 06:52
    Have you considered using an SX instead of a PIC? In this case, you could easily have a much larger buffer in software by using an SX instead of a PIC. Also, you might find that you can learn more while saving money.

    Of course, you have to get started with Parallax's IDE. They do have SX/C now. You may even eventually want to program in Assembler to get all the complete flexiblity that virtual peripherals programing can provide.

    The SX-28 is quite similar to a generic PIC, but the SXes have a bit more robust I/O if you are concerned with damage. One of the reasons for Parallax's success is that the chips are among the most difficult to damage - ideal for a beginner.

    The SXes also have more RAM and more EEPROM than similar PIC counterparts.

    By generic I mean that you don't have a hardware USART. But you can create a software USART with the virtual peripherals approach. SXList.com is very helpful for moving over from PICs to SXes if you want to learn Assembler.

    The big advantage of the SX-28 and SX-48 is that you don't have to waste money buying different features and waste time learning a different chip. You just provide the appropriate firmware and become a superior firmware programmer in the process. Both are faster than PICs and can use that extra speed to create similar hardware features with virtual peripherals.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    It's sunny and warm here. It is always sunny and warm here.... (unless a typhoon blows through).

    Tropically, G. Herzog [noparse][[/noparse] 黃鶴 ] in Taiwan
Sign In or Register to comment.