Wireless 433MHZ RF on PIC16
julidela
Posts: 3
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.
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
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.
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;
}
}
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:
2) Change SPBRGL = 0x25
3) Add:
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:
Regards