|
|
View previous topic :: View next topic |
Author |
Message |
TheRidDler
Joined: 13 Jun 2007 Posts: 7
|
RF Interrupt Advice |
Posted: Tue Jun 19, 2007 1:28 pm |
|
|
Hi all! I received a copy of one of my friends' code to control RF operations between a 18F252 PIC and a PC. The code is faulty however. Could you please help me in getting the bugs out, as i am totally new to programming pics and trying to understand this. One problem that i can see is that the timer 3 interrupt is being enabled, but is called nowhere. Any advice?
Code: | #define RF_TXD PIN_A0
#define RF_RXD PIN_A1
void RX_Sel(int s)
{
switch( s )
{
case 0:
output_low(PIN_C0);
break;
case 1:
output_high(PIN_C0);
break;
}
}
void TX_Sel(int s)
{
switch( s )
{
case 0:
output_low(PIN_C1);
break;
case 1:
output_high(PIN_C1);
break;
}
}
void Receive()
{
int counter = 0x00, position = 0x00;
char Header[3] = {0x00,0x00,0x00};
char Identifier = 0x00;
char Received[];
int RFtimeout = 20;
for (counter=0;counter<128;counter++)
Received[counter] = 0x00; // Clears the received string so that
// new data can be read
counter = 0x00;
#use rs232(baud=9600,parity=N,xmit=RF_TXD,rcv=RF_RXD,bits=8,RESTART_WDT,errors) // data from PC to PIC
RX_Sel(0); //Enable Receiver, activated on low..
//WAITING RX ROUTINE..
set_timer3(0x0000); //Set up Timer 3
timeout = 0;
enable_interrupts(int_TIMER3); //Switched on Timer 3 interrupt
enable_interrupts(global); //Switches on all interrupts
WAIT:
//WAITING RX ROUTINE
Header[0] = getchar(); //Wait till char 1 of received string
//found on RX pin
IF (timeout > RFtimeout)
{ //String is discarded if not found within
disable_interrupts(int_TIMER3); //specified timeout
timeout = 0;
RFIndicator = 0x01; //This is the timeout and well received
goto OUT; //indicator
}
IF (Header[0] != 0xCC) //First checksum char must be 0xCC
goto WAIT;
Header[1] = getchar(); //Next char to be received
IF (timeout > RFtimeout)
{
disable_interrupts(int_TIMER3);
timeout = 0;
RFIndicator = 0x01; //Timeout and well received indicator
goto OUT;
}
IF(Header[1] != 0x33) //Second checksum char must be 0x33
goto WAIT;
Header[2] = getchar();
IF (timeout > RFtimeout)
{
disable_interrupts(int_TIMER3);
timeout = 0;
RFIndicator = 0x02; //Timeout and well received indicator
goto OUT;
}
IF(Header[2]!= 0x55) //Third checksum char must be 0x55
goto WAIT;
Identifier = getchar(); //Identifier byte (Address of the
//listeting module)
IF (timeout > RFtimeout)
{
disable_interrupts(int_TIMER3);
timeout = 0;
RFIndicator = 0x03; //Timeout and well received indicator
goto OUT;
}
IF (Identifier != Address) //If Address mismatch WAIT
goto WAIT;
Identifier = 0x00;
disable_interrupts(int_TIMER3);
While (counter < 128) //Checksum Complete.
{ //Now data is read in.
Received[counter] = getchar();
counter++;
}
RX_Sel(1); //Receiver switched OFF
counter = 0x00;
while (counter < 64) //Decode Data
{
DecodedData[position] = decodeRF(Received[counter],Received[counter+1]); //decodeRF function return byte for byte
position++;
counter = counter + 2;
}
RFIndicator = 0x00; //Timeout and well received indicator
OUT: //Out Routine
disable_interrupts(global); //Disables all interrupts
}
void Transmit(char IDUnit)
{
int8 i = 0;
set_tris_c(0x80);
#use rs232(baud=9600,parity=N,xmit=RF_TXD,rcv=RF_RXD,bits=8,RESTART_WDT,errors)
delay_ms(40); //Give Relay Unit time to change TRX to RX
TX_Sel(0); //Transmitter ON
delay_ms(5);
for (i=0;i<200;i++) //Training sequence
putc(0xAA); //Sends 0xAA chars to confirm Txmit
putc(0xFF);
putc(0xFF);
putc(0xCC); //Header #1
putc(0x33); //Header #2
putc(0x55); //Header #3
putc(IDUnit); //ID of unit to be communicated to
for (i=0; i<128; i++) //Data
putc(EncodedData[i]);
putc(0x00); //Ending Sequence of transmition
putc(0x00);
TX_Sel(1); //Transmitter OFF
for (i=0;i<64;i++)
{ //clear the TX buffer for next transmission
ToBeSend[i] = 0x00;
}
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jun 19, 2007 4:34 pm |
|
|
My advice is to find some radio units that are compatible to the Nordic
brand units. Then do a web search for CCS code. The Nordic brand
doesn't seem to have much sample code available. |
|
|
TheRidDler
Joined: 13 Jun 2007 Posts: 7
|
A more crucial problem... |
Posted: Tue Jun 19, 2007 4:48 pm |
|
|
Thnx PCM, ill look into that now... i have however ran into another problem much greater along the way.
Here is my setup: Im using a remote board with Radiometrix RF transmitter and receiver. The datasheets for them can be found here :
http://www.radiometrix.co.uk/dsheets/tx2arx2a.pdf
At the PC side i have a nRF905 tranceiver unit:
http://www.mpfreezone.com/downloads/files/RS232-RFmanual1.22.pdf
On my remote board i receive GPS data. I would like to Manchester encode the data and send it to the tranceiver at PC side. This does not pose to be such a big problem,
HOWEVER
The tranceiver unit at PC side has built-in CRC, Address and Preamble capabilities. All said and done i encode my data at remote side, include a
chosen crc, address and preamble and send it away, but dont know the crc, address or preamble of the tranceiver unit! I am correct in saying that
if these 3 don't match, nothing much is going to happen!
ANY advice as to how to get these values from the tranceiver unit?
This is my first RF project and im really still learning, but the problem seems simple enough.
Thank you all for helping a stranger!! |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|