Shop OBEX P1 Docs P2 Docs Learn Events
Wireless 433MHZ RF on PIC16 — Parallax Forums

Wireless 433MHZ RF on PIC16

julidelajulidela Posts: 3
edited 2012-02-19 12:02 in Accessories
hi everyone,

We are trying to setup the rf antennae to be used with a PIC Processor. After setting up all the registers, the PIC still doesn't seem to get any of the data being sent to it. It constantly gets garbage. We have another receiver connected to a BASIC Stamp that has no problem receiving the correct data. Has anyone ever tried using the antennae with a PIC?

The PIC is using a 16MHz clock and we are trying to have a baud rate of 9600. We are setting up the registers associated with USART like so:
SPBRGL = 0x69;
SPBRGH = 0x00;
BAUDCON = 0x00;
RCSTA = 0x90;
TXSTA = 0x24;

Thank You.

Comments

  • micro_engineermicro_engineer Posts: 7
    edited 2012-02-17 20:02
    When you write "rf antennae" I assume you mean the Parallax RF transceiver module, right?

    At any rate, there is some information missing from your post regarding the PIC:

    - Which PIC is it?
    - I assume the 16MHz oscillator is from an external crystal, right?
    - What are your config bits set to?
    - Does an RX overflow occur?

    ...and one of the most important:
    - Did you set the UART RX pin you're using to DIGITAL mode vs. analog mode? (if applicable to your PIC-see data sheet)

    It would be hard to help you more without more info about the details & all of your configuration code.

    More than likely you have a) incorrect baud rate setting, or b) incorrect set up of the UART peripheral and/or other registers.

    If you are getting garbage and some type of changing data it sounds likes like it is probably (a). As long as the PIC is set up correctly it should be very simple to get the data.

    It would be very beneficial to verify your baud rate by sending something via the UART to another "known good device" or a com port terminal program. And send something back to the PIC.
  • julidelajulidela Posts: 3
    edited 2012-02-18 13:49
    Thanks for your quick response!

    Yes it is the parallax RF transceiver im using.

    A little more information:
    The pic is the PIC16F1519, running with a 16MHz clk and I believe there is no overflow.

    the other config bits i'm using are:

    WDTE_OFF
    PWRTE_ON
    MCLRE_ON
    CP_OFF
    BOREN_OFF
    CLKOUTEN_OFF
    IESO_OFF
    FCMEN_OFF

    The RX pin is set to digital input. I think as well the problem might be on the baud rate setting.

    I'm attachin the very basic code im using to test now. once i get the RF working properly i will add parity and CRC (at least 3-4 bit) to make sure the data is reliable.

    #include <htc.h>


    int state = 0;


    void main(void){
    TRISB = 0x00;
    ANSELB = 0x00;
    PORTB = 0x00;
    TRISC = 0x80; //RX pin input
    ANSELC = 0x00;

    SPBRGL = 0x69;
    SPBRGH = 0x00;
    BAUDCON = 0x00;
    RCSTA = 0x90;
    TXSTA = 0x24;

    INTCON = 0xC0;
    PIE1 = 0x20;
    PIR1 = 0x00;


    while(1);
    }


    static void interrupt
    isr(void){
    int x = 0;
    if(RCIF) {
    x = RCREG;
    if ((state == 0) && (x == 'n')){
    state = 1;
    }
    else if (state == 1){
    PORTB = x;
    state = 0;
    }
    PIR1 = 0x00;
    }
    }
  • julidelajulidela Posts: 3
    edited 2012-02-18 14:09
    also what i forgot to mention is I'm sending two bytes. the first one has the character n, the second one is just a number im reading in some led's on port b
  • micro_engineermicro_engineer Posts: 7
    edited 2012-02-19 12:02
    Hello there. I see several errors. Also you didn't specify if the 16MHz is the internal one or an external crystal (as I mentioned before). It is extremely important to be specific for these devices when asking for help, please.

    Let me start with these:

    1) It appears you haven't set the configuration bit setting for oscillator selection

    2) You haven't selected the internal oscillator prescale in OSCCON. Therefore *if* you are using the internal 16MHz oscillator you are using the default prescale, which sets the Fosc value to be 500KHz, not 16MHz.

    3) Where did you get that value for SPBRGL? If you take the data sheet example, for a 16MHz value for Fosc, it should be 25d (0x19) not 105d (0x69) for 9,600 baud rate

    So you need to do the following, at least:

    1) Add to the config bit settings:
    FOSC_INTOSC
    

    2) Change SPBRGL = 0x25

    3) Add:
    OSCCON |= 0x78; /*  IRCF bits:  Set the oscillator select multiplexer to Fosc / 1 (16MHz)  */
    

    I think that might be all.


    Also:

    A) "int" data members aren't needed for dealing with the UART unless you are using 9-bit mode. Recommend unsigned char data size.

    Personally in order to get the RX functionality working, I would not use interrupts probably until I know the RX is ok.

    I would do something like this:
    enum UART_state_values {WAIT_STATE, RX_DATA_STATE};
    
    unsigned char ucRXData;
    unsigned char ucUART_state;
        
    ucUART_state = WAIT_STATE;
    
    while(1)
    {       /*  State machine to wait for a valid start of message ('n' character) and write the next byte, if received, to a port */
            switch(ucUART_state)
            {
                case WAIT_STATE:
                    /*  Wait for start of message; if received, continue.  Else, start over  */
                    while(!RCIF);
                    RCIF = 0;
                    ucRXData = RCREG;
                    if(ucRXData == 'n')
                    {   ucUART_state = RX_DATA_STATE;  }
                    else
                    {   ucUART_state = WAIT_STATE;      }
                    break;
    
                case RX_DATA_STATE:
                   /*  Start of messge was received so the next byte should be a data byte; write this to the port pins when received,
                        then reset the state machine state value */
                    while(!RCIF);
                    RCIF = 0;
                    ucRXData = RCREG;
                    PORTB = ucRXData;
                    ucUART_state = WAIT_STATE;
                    break;
    
                default:
                   /* Default for being in an unknown state */
                    ucUART_state = WAIT_STATE;
                    break;
            }
    }
    
    

    Regards
Sign In or Register to comment.