Full Duplex communication between 2 pic16f877a using RF

Bluetooth, XBee, RF......

Full Duplex communication between 2 pic16f877a using RF

Postby sysysy » Thu Mar 31, 2011 2:47 am

Hi,

I'm using 2 pair of RF (315Mhz and 433Mhz) rf module trying to make a full duplex communication between 2 PIC 16F877A ( datasheet say that UART support full duplex communication)

But when come to a practical, i am having problem, i cant figure out what is the problem.

Everything work well when in half duplex communication.

Anyone know what extra step need to take care for full duplex comm? :( :( :(

is it coding part also will be a most crucial part? please advice.

Thanks.
sysysy
Novice
 
Posts: 16
Joined: Wed Oct 27, 2010 9:09 pm

Re: Full Duplex communication between 2 pic16f877a using RF

Postby sich » Thu Mar 31, 2011 9:49 am

Try to connect your mcu one-by-one to the PC terminal to check the communication, without RF modules. You need to know where's the problem.
~> How to ask QUESTIONS the SMART way in FORUM? <~
User avatar
sich
Moderator
 
Posts: 603
Joined: Tue Apr 21, 2009 2:15 pm

Re: Full Duplex communication between 2 pic16f877a using RF

Postby Kromuald13 » Thu Dec 15, 2011 3:50 am

Hi to All
i am Romuald , and i am doing a RF based project . My aim is to send a string of character ( 4 bit code) in a wireless manner .
to do so , i used DIP switch to produce the 4 bit code on the transmitter side and connect them to PORT A , then i want to send t a receiver .
i have already programmed it , and it compiles succesfully , but i don't know why when i check at the receiver side , but using LEDs i can 't see anything
it is seen no to be working at all

here below follows my codes


TRANSMISSION
CODE: SELECT_ALL_CODE
//==========================================================================
//   Author            : Cytron Technologies      
//   Project            : Sending Data using RF Module
//   Project description   : The transmitter will send 0->F (data in Hexadecimal)
//==========================================================================

//===================================================================================
//   include
//===================================================================================
#include <pic.h>

//===================================================================================
//   configuration
//===================================================================================
__CONFIG (0x3F32);

//===================================================================================
//   define
//===================================================================================



#define SYNC_DATA      0x00
#define HEADER         0xaa
#define send_button         RB0

//===================================================================================
//   function prototype
//===================================================================================
void uart_send(unsigned char data);
void send_packet(unsigned char data);

//   main function
//===================================================================================
void main(void)
{
   //assign variable
   unsigned char Adress,no;
                           

   ADCON1= 0x06;            //configure PortA as digital I/O

   TRISA = 0b111111;         //configure PORTA input
   TRISB = 0b00000001;         //configure PORTB as output
   
   //setup USART
   BRGH = 0;               //baud rate low speed option
   SPBRG = 255;            //set boud rate to 1200bps for 20Mhz crystal
   TX9 = 0;               //8-bit transmission
   TXEN = 1;               //enable transmission
   SYNC = 0;               //asynchronous
   
   SPEN = 1;               //enable serial port
   
   Adress = PORTA;   
   no=0;


   while(1)                  //infinity loop
   {
   no = Adress;

   if (send_button ==0){
         
      send_packet(no);
                       }    
   }      
}

//===================================================================================
//   functions
//===================================================================================
void uart_send(unsigned char data)
{   
   while(TXIF==0);            //only send the new data after
   TXREG=data;               //the previous data finish sent
}


void send_packet(unsigned char data)
{
   unsigned char i;
   
   // Buffer for the data in one packet.
   unsigned char buffer[3];
   
   // Byte 0 is the header.
   buffer[0] = HEADER;
   
   // Byte 1 is the data.
   buffer[1] = data;
   
   // Byte 2 is the checksum.
   buffer[2] = (unsigned char)(HEADER + data);
   
   // Clocking for a while before sending the data so that the Tx and Rx are in sync.
   for (i = 0; i < 7; i++) uart_send(SYNC_DATA);
   
   // Transmit the packet using UART.
   for (i = 0; i < 3; i++) uart_send(buffer[i]);
}


RECEPTION
CODE: SELECT_ALL_CODE
//   include
//===========================================================================
#include <pic.h>

//===========================================================================
//    configuration
//============================================================================
__CONFIG (0x3F32);

//============================================================================
//   define
//============================================================================

#define HEADER         0xaa
# define Adress                 PORTA
//=============================================================================
//   function prototype
//=============================================================================
unsigned char uart_rec(void);
unsigned char read_packet(void);

//============================================================================
//   main function
//============================================================================
void main(void)
{
   //assign variable
   unsigned char Adress,no;
                              

   //set I/O input output
   TRISB = 0b00000000;         //configure PORTB as output
         TRISA = 0b000000;
   
      
   //setup USART
   BRGH = 0;               //baud rate low speed option
   SPBRG = 255;            //set boud rate to 1200bps for 20Mhz crystal
   SPEN = 1;               //enable serial port
   RX9 = 0;               //8-bit reception
   CREN = 1;               //enable reception

   Adress = 0 ;
   

   while(1)               //infinity loop
   {
      CREN=1;                     //enable continuos receive
      if(OERR==0) no=read_packet();       //receive sata if overrun error free
      else CREN=0;               //if overrun error, disable continuos receive
      
      Adress=no;         
     
   }
}

//==================================================================================
//   functions
//===================================================================================
unsigned char uart_rec(void)   //receive uart value
{
   unsigned char rec_data;
   while(RCIF==0);            //wait for data
   rec_data = RCREG;
   return rec_data;         //return the received data
}



unsigned char read_packet(void)
{
   // Buffer for received byte.
   unsigned char received_byte;
   
   // Counter to indicate the current position of the received data packet.
   static unsigned char counter = 0;
   
   // Buffers for the data and checksum.
   unsigned char data;
   unsigned char checksum;
   
   
   // We loop until the checksum is correct.
   do {
      // We will ignore the sync data and assume the header byte is the start of packet.
      // Keep reading until the header byte is received.
      while (uart_rec() != HEADER);
      
      // The following byte shoulde be the data byte.
      data =    uart_rec();
      
      // Then the last byte is the checksum.
      checksum =    uart_rec();
   } while (checksum != (unsigned char)(HEADER + data));
   
   // If the checksum is correct, return the data.
   return data;
}
Kromuald13
Novice
 
Posts: 26
Joined: Wed Feb 09, 2011 2:03 am


Return to Wireless Device

Who is online

Users browsing this forum: No registered users and 10 guests