Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to frame a packet in RF transmission?

Status
Not open for further replies.

areeckal

Member level 2
Joined
Jan 22, 2011
Messages
42
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,567
I need to set up Rf communication from a pic 18F to another pic 18F.
The data i need to send is a synchronization byte, address byte, data and checksum. My doubt is how should i frame a packet. Should i load the above format using 8 bits and load TXREG one time or should i send each as a byte loading TXREG one after another? Pls help. Also how the data should be written in TXREG? As hex or char or binary?
 

what RF device are you using and how is it connected to the PIC18?
 

I am using a RF transmitter- receiver module. I am connecting my transmitter to the tx pin of pic 18F and receiver to the rx pin of another pic 18F.
 

Your first post stated "The data i need to send is a synchronization byte, address byte, data and checksum.". I assume the documentation of your RF device specified this frame format. You could have an array of unsigned char (in effect bytes) called say data[]. data[0] for be the synchronization, data[1] would be the address, etc etc. As you put the data in the array you would need to calculate the checksum and put it in the last byte. You then send the bytes to the UART.
 

RF device hasn't have any documentation. I got to know while RF transmission i need to have error detection mechanism.
If i am storing it as a character, how can i assign binary numbers to each byte? Say for eg. i need synchronization byte=10101010
 

you just assign values, a char is an 8 bit integer, e.g.
Code:
    unsigned char data[100];
    data[0]=0xAA;    // sync 10101010
unsigned char APIdata[100]; // hold API data

here an example setting up an Zigbee frame for an XBee device
Code:
// send API Transmit Request frameID to address - API data is in *data
void APItransmitRequest(int frameID, long int addressMSB, long int addressLSB, const unsigned char *data, int length) 
{
    int i;
    printf("API Transmit Request RAM frame %0x length %d bytes to address %0lx%0lx :\n  ", frameID, length, addressMSB, addressLSB);
    APIdataindex=0;										// initialise API data index to 0
	APIdata[APIdataindex++]=0x10;						// XBee transmit request			
	APIdata[APIdataindex++]=frameID;					// frame ID
	APIdata[APIdataindex++]=(addressMSB>>24) & 0xFF;	// address MSB
	APIdata[APIdataindex++]=(addressMSB>>16) & 0xFF;
	APIdata[APIdataindex++]=(addressMSB>>8)  & 0xFF;
	APIdata[APIdataindex++]=(addressMSB)     & 0xFF;
	APIdata[APIdataindex++]=(addressLSB>>24) & 0xFF;	// address LSB
	APIdata[APIdataindex++]=(addressLSB>>16) & 0xFF;
	APIdata[APIdataindex++]=(addressLSB>>8)  & 0xFF;
	APIdata[APIdataindex++]=(addressLSB)     & 0xFF;
	APIdata[APIdataindex++]=0xFF;						// broadcast network address
	APIdata[APIdataindex++]=0xFE;
	APIdata[APIdataindex++]=0x00;						// hops byte
	APIdata[APIdataindex++]=0x00;						// options byte
    for(i=0; i<72 && i<length; i++)					// data to transmit
		{
         APIdata[APIdataindex++]=data[i];
         if(APIdataindex>98)
             { printf("\n\n ********* In APItransmitRequest() APIdataindex[] overflow   ********* \n\n"); break; }
        }      
	APIdata[APIdataindex++]=0x0;						// ???
    APIcommand(APIdataindex, APIdata);					// send APIdata length APIdataindex
    XBeeLCDstatusROM( "Node xmit data"); 
}
 

Actually, Iam using USART for presenting the data serially to the tx pin.
In the USART header,
a function USARTWriteByte(char ch) is used to write to the TXREG
function definition is:
USARTWriteByte(char ch)
{
while(!TXIF);
TXREG=ch;
}
 

the following function (called in my last post) used the USART to transmit the bytes
Code:
// send  API command in data[] length dataLength to XBee 
static void APIcommand(int dataLength, unsigned char data[])
{
    unsigned char checksum=0;
	int i;
	USARTWriteByte(0x7E);						// send 0x7E
	USARTWriteByte((dataLength >> 8) & 0xFF);	// send length MSB	
	USARTWriteByte(dataLength & 0xFF);			// send length LSB
  	for(i=0; i < dataLength; i++)				// send data bytes
       {
        checksum += data[i];					// calculate checksum
        USARTWriteByte(data[i]);
       }
    USARTWriteByte(0xFF-(checksum & 0xff));		// send checksum
}
this also shows the checksum being calculated
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top