CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

RF communication problem (serial)

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
rnome



Joined: 18 Dec 2006
Posts: 20
Location: europe (Turkey)

View user's profile Send private message

RF communication problem (serial)
PostPosted: Thu Sep 20, 2007 9:43 am     Reply with quote

hi everybody

i m trying to send 6 bytes via serial
but whatever i done it didnt work correct.

i wrote this codes for reciever side

Code:
#include <16F877.h>
#use delay(clock=4000000)
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use rs232(baud=2400,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#include <lcd.c>

int data[6], x;
int1 data_come=0;
int count=0,index=0;

#INT_RDA
void RDA_isr()
{
   x=getc();
   
   if(data_come==1){
            data[index]=x;
          index++;
            if(index>=6){
               index=0;
               data_come=0;
          }
   }
      
   if(x==85)      //85 is preamble
      count++;       //  if one after the other 5 unit 85 come count
   else            //  reaches 5. else count already 0.
      count=0;   
 
   if(count==5){      //if count equal to 5
      count=0;          //data_come is set to take datas in a array
      data_come=1;
      } 
}

void main( void )
{
   lcd_init();
   output_high(pin_d2);

   enable_interrupts(int_rda); 
   enable_interrupts(GLOBAL);
   
   for(;;){
     lcd_gotoxy(1,1);
     printf(lcd_putc, "%u,%u,%u,   \n%u,%u,%u   ",data[0],data[1],data[2],data[3],data[4],data[5]);
     }
}


i must follow communication protocol of my RF modules
at first 5 bytes preamble must send to wake up RF hardware
after these 5 bytes i can send my 6 bytes
preamble codes are unimportant and i dont want to take them

and these codes for transmitter

Code:
#include <16F877.h>
#fuses Xt,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=2400,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

int d0=10, d1=20, d2=30, d3=40, d4=50, d5=60;
int dizi[6]={10,20,30,40,50,60};

void send()
{int i;
    for(i=0;i<5;i++)
    {
    putc(85);      // 5 byte preamble
    }
    putc(d0);      //datas
    putc(d1);
    putc(d2);
    putc(d3);
    putc(d4);
    putc(d5);
}

void main()
{
   output_high(pin_B6);
   for(;;)
   {   
      send();
      delay_ms(800);
    }
}

_________________
live fast, never rest and do your best
libor



Joined: 14 Dec 2004
Posts: 288
Location: Hungary

View user's profile Send private message

PostPosted: Thu Sep 20, 2007 10:10 am     Reply with quote

At first glance:
A preamble in RF communication should be alternating 0s and 1s, like 0x55. The preamble is used by the receiver module to tune on to the correct datarate.
In your receiver code you rely on receiving the preamble correctly. This is usually not possible, the beginning of the preambles gets lost, this is what they are for.
I think there is a further problem of detecting the byte boundaries correctly.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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