AtomSoft
Well-Known Member
Hey guys i have been going crazy over something that is supposed to be simple... I bought these 2 wireless parts. One Transmitter and One Receiver.
RECEIVER: SparkFun Electronics - RF Link 4800bps Receiver - 315MHz
TRANSMITTER: SparkFun Electronics - RF Link Transmitter - 315MHz
The RECEIVER says data rates UPTO 4800bps so i assume 2400bps is fine. If anything i can alter the code to send at 4800bps and receive at same. If anyone thinks that can be the issue.
Im not sure which side is not working or if both are not. I have placed my code for both below. I checked the BAUD (SPBRG) numbers and they seem to be correct.
The 18F2525 (TRANSMITTER) is running at 40Mhz
The 18F248 (RECEIVER) is running at 10Mhz
My problem is the receiver is not getting my data and every time i check RCSTA on the RECEIVER i am getting a FRAMING ERROR...
The TRANSMITTER has 2 BUTTONS to send a 0x01 and a 0x02 and a LED to show me when a send is complete.
The Receiver is in DEBUG mode to catch what data is coming.
TRANSMITTER CODE:
RECEIVER CODE:
RECEIVER: SparkFun Electronics - RF Link 4800bps Receiver - 315MHz
TRANSMITTER: SparkFun Electronics - RF Link Transmitter - 315MHz
The RECEIVER says data rates UPTO 4800bps so i assume 2400bps is fine. If anything i can alter the code to send at 4800bps and receive at same. If anyone thinks that can be the issue.
Im not sure which side is not working or if both are not. I have placed my code for both below. I checked the BAUD (SPBRG) numbers and they seem to be correct.
The 18F2525 (TRANSMITTER) is running at 40Mhz
The 18F248 (RECEIVER) is running at 10Mhz
My problem is the receiver is not getting my data and every time i check RCSTA on the RECEIVER i am getting a FRAMING ERROR...
The TRANSMITTER has 2 BUTTONS to send a 0x01 and a 0x02 and a LED to show me when a send is complete.
The Receiver is in DEBUG mode to catch what data is coming.
TRANSMITTER CODE:
Code:
/* *****************************************************************************
; *
; Filename: *
; Date: *
; File Version: 001 *
; *
; Author: Jason Lopez *
; Company: AtomSoft *
; *
;***************************************************************************** */
#include <p18f2525.h>
#include <delays.h>
#include <string.h>
#pragma config WDT = OFF, LVP = OFF, OSC = HSPLL
/************************************
Prototypes
*************************************/
void main(void);
void SendUART(unsigned char data);
void init_uart(void);
void delay_ms(int count);
#define BTN1 PORTBbits.RB1
#define BTN2 PORTBbits.RB2
#define LED LATCbits.LATC3
void main(void){
ADCON1 = 0x0F;
TRISB = 0b00000110;
TRISC = 0x00;
init_uart();
while(1){
if(BTN1){
LED = 1;
delay_ms((int)500);
while(BTN1);
SendUART(1);
LED = 0;
}
if(BTN2){
LED = 1;
delay_ms((int)500);
while(BTN2);
SendUART(2);
LED = 0;
}
}
}
//417us bit for 2400bps
void init_uart(void){
TRISC = 0b10000000;
TXSTAbits.SYNC = 0;
BAUDCTLbits.BRG16 = 0;
TXSTAbits.BRGH = 0;
SPBRG = 255; //2400bps
TXSTAbits.TXEN = 1; //ENABLE TX
RCSTAbits.CREN = 1; //ENABLE RX
RCSTAbits.SPEN = 1; //ENABLE SERIAL PORT and PIN Config
PIR1 = 0x00;
}
void SendUART(unsigned char data){
while(!TXSTAbits.TRMT);
TXREG = data;
PIR1 = 0x00;
}
void delay_ms(int count){
int x;
for(x=0;x<count;x++){
Delay100TCYx(99);
}
}
Code:
/* *****************************************************************************
; *
; Filename: *
; Date: *
; File Version: 001 *
; *
; Author: Jason Lopez *
; Company: AtomSoft *
; *
;***************************************************************************** */
#include <p18f248.h>
#include <delays.h>
#include <string.h>
#pragma config WDT = OFF, LVP = OFF, OSC = HS
/************************************
Prototypes
*************************************/
void main(void);
void SendUART(unsigned char data);
unsigned char GetUart(void);
void init_uart(void);
void delay_ms(int count);
void main(void){
unsigned char data;
ADCON1 = 0x0F;
TRISB = 0b00000110;
TRISC = 0x00;
init_uart();
while(1){
data = 0;
data = GetUart();
delay_ms(100);
if(data)
Nop();
}
}
void init_uart(void){
TRISC = 0b10000000;
TXSTAbits.SYNC = 0;
TXSTAbits.BRGH = 0;
SPBRG = 64; //2400bps
TXSTAbits.TXEN = 1; //ENABLE TX
RCSTAbits.CREN = 1; //ENABLE RX
RCSTAbits.SPEN = 1; //ENABLE SERIAL PORT and PIN Config
PIR1 = 0x00;
}
void SendUART(unsigned char data){
while(!TXSTAbits.TRMT);
TXREG = data;
PIR1 = 0x00;
}
unsigned char GetUart(void){
unsigned char temp = 0;
while(!PIR1bits.RCIF)
temp = RCREG;
if(RCSTA & 0b00000110){
//ERRORS
RCSTAbits.CREN = 0;
delay_ms(1);
RCSTAbits.CREN = 1;
}
return temp;
}
void delay_ms(int count){
int x;
for(x=0;x<count;x++){
Delay100TCYx(99);
}
}