[SOLVED] PIC to PIC RF Communication Fails (PIC16F628A)

Discussion on projects that are created by users and posted on mikroElektronika website.
Post Reply
Author
Message
PIC16F84A
Posts: 17
Joined: 18 Jun 2016 23:44

[SOLVED] PIC to PIC RF Communication Fails (PIC16F628A)

#1 Post by PIC16F84A » 01 Sep 2016 00:14

I've got two PIC16F628A.
one for transmitter and one for receiver... (433 MHz)

I set B pins as input in order to use transmitter and receiver...
The codes are written in mikroC.



Here is the code for the transmitter:

Code: Select all

void main() {

     trisb = 1;
     portb = 0;
     cmcon = 7;
     
     UART1_Init(9600);
     delay_ms(1000);
     
     while(1){
              UART1_Write_Text('a');
              delay_ms(1000);
              UART1_Write_Text('b');
              delay_ms(1000);
     }

}
Here is the code for the receiver:

Code: Select all

void main() {

     trisb = 1;
     trisa = 0;
     portb = 0;
     porta = 0;
     cmcon = 7;

     UART1_Init(9600);
     delay_ms(100);
     while(1){

              if(UART1_Data_Ready()){
                     if(UART1_Read() == 'a') porta.b1 = 1;
                     if(UART1_Read() == 'b') porta.b1 = 0;
              }

     }

}
I want to light the led on when I get message 'a' from transmitter and light led off when message 'b' is received.
The led is connected to 18.pin (porta.b1).

EDIT


I have no proteus...
That's why I drew the diagram of the circuits on a paper.

Image

EDIT

The problem is solved; thanks...
Apparently, it is a obligation to connect an antenna to transmitter.
There is a hole at transmitter's right-top side.
I connected a jumper cable there and It worked.
When I touch the hole with my finger, the same happens.
But for long distances, transmitter needs an antenna.
But when the transmitter is near the receiver; finger, copper wire is enough.

Those codes work well: (It is quote from https://mikrodunya.wordpress.com/2011/11/08/udea-nin-rf-veri-iletimi-alanindaki-kucuk-devleri-atx-34-nrx-34/)

Receiver:

Code: Select all

char az,i=0, msg[6];
void main()
{
 UART1_Init(2400);
 trisb.f0=0;
 portb.f0=1;
 delay_ms(100);
 
 while(1)
         {
          if(UART1_Data_Ready())
          {
           msg[i]=UART1_Read();
           if(msg[0]=='y' || msg[0] == 's')//Eğer msg[0] 'y' veya 's' ise i değişkeninin 1 arttır.
                                           {
                                            i++;
                                           }
          }
          if(i==3)
                  {
                   if(msg[0]=='y' && msg[1]=='a' && msg[2]=='n' )portb.f0=1;  //Senkron için gönderilen sıfır veya 255 aranmaz....
                   if(msg[0]=='s' && msg[1]=='o' && msg[2]=='n' )portb.f0=0;
                   i=0;
                   msg[0]=0;
 
                  }
         }
}
Transmitter:

Code: Select all

char pre[15]={'U','U','U','U','U',255,255,255,255,255,0,0,0,0,0};
char yak[3]={'y','a','n'};  //Senkron için en az bir byte sıfır gönder kesinlikle.....
char son[3]={'s','o','n'};
char i=0,j=0;
 
void kurulum()
{
 UART1_Init(2400);
 trisb.f0=1;
 Delay_100ms();
 
}
 
void main()
{
 kurulum();
 while(1)
       {
         if(portb.f0)
         {
          for(i=0;i<15;i++)
                           {
                            UART1_Write(pre[i]);
                           }
          for(j=0;j<10;j++)                   //garanti olması açısından 10 kez gönderiliyor veriler...
          {
                          for(i=0;i<3;i++)
                          {
                           while(!UART1_Tx_Idle());
                           UART1_Write(yak[i]);
                          }
          }
         }
 
          //*************************************************************
         if(!portb.f0)
         {
          for(i=0;i<15;i++)
                           {
                            UART1_Write(pre[i]);
                           }
          for(j=0;j<10;j++)
          {
                         for(i=0;i<3;i++)
                         {
                          while(!UART1_Tx_Idle());
                          UART1_Write(son[i]);
                         }
          }
         }
       }
}
The website above is written in Turkish language.
You can translate it using google translate...
Last edited by PIC16F84A on 08 Sep 2016 18:51, edited 4 times in total.

User avatar
Aleksandar.Mitrovic
mikroElektronika team
Posts: 1697
Joined: 11 Mar 2015 12:48

Re: PIC to PIC RF Communication Fails (PIC16F628A)

#2 Post by Aleksandar.Mitrovic » 01 Sep 2016 13:22

Hi,

Can you please tell me which transmitter and receiver are you using exactly?

For the transmitter, please connect the VCC and GND if you didn't.

For receiver, also.

Check for the transceiver and receiver which you use on which baud rate working.

Kind regards,
Aleksandar

PIC16F84A
Posts: 17
Joined: 18 Jun 2016 23:44

Re: PIC to PIC RF Communication Fails (PIC16F628A)

#3 Post by PIC16F84A » 01 Sep 2016 14:37

I am using these ones : http://rayshobby.net/cart/433-rf

Yes, I had already connected VCC and GND.

I checked the transmitter and receiver through arduino and both of them are working at baud rate 9600.

Thanks..

PIC16F84A
Posts: 17
Joined: 18 Jun 2016 23:44

Re: PIC to PIC RF Communication Fails (PIC16F628A)

#4 Post by PIC16F84A » 02 Sep 2016 09:48

I succeeded to light on the led but at this time It doesn't light on according to my desire.

The problem I told is about the low power of battery, I think.

Now, I work with other batteries in order to get enough power...

New receiver code:

Code: Select all

char x;
void main() {

     trisb = 0xFF;
     trisa = 0;
     trisa.b5 = 1; //MCLR pini için
     cmcon = 7;
     porta = 0;
     porta.b5 = 1;

     UART1_Init(9600);
     delay_ms(100);

     while(1){

              if(UART1_Data_Ready()){

                  x = UART1_Read();

                  if (x == 'a') porta.b1 = 1;
                  if (x == 'b') porta.b1 = 0;

              }

     }

}
New transmitter code:

Code: Select all

void main() {

     trisb = 0xFF;
     trisa = 0;
     trisa.b5 = 1; //MCLR 
     porta = 0;
     porta.b5 = 1; //MCLR

     cmcon = 7;

     UART1_Init(9600);
     delay_ms(100);


     while(1){
              UART1_Write_Text("a");
              delay_ms(1000);
              UART1_Write_Text("b");
              delay_ms(1000);

     }

}
According to these codes, the led should light on for 1 second and off for 1 second...

But It wasn't so. When I touch the cables which are connected to receiver, the led lit on or off.

Sometimes it does it without touching...

Even if transmitter circuit is disabled, the led in receiver circuit lights on or off itself...

It doesn't have a specific lighting on type. It does it according to its decision.

User avatar
Aleksandar.Mitrovic
mikroElektronika team
Posts: 1697
Joined: 11 Mar 2015 12:48

Re: PIC to PIC RF Communication Fails (PIC16F628A)

#5 Post by Aleksandar.Mitrovic » 02 Sep 2016 17:25

Hi,

We do not use this receiver and transmitter therefore I can not make any test.

I suggest you to try to use some lower baud rate to test your hardware, be sure that you have set your PIC16 correctly and that your baud rate is good.

Maybe some other users have worked with this hardware and have some advice for you. I suggest you to try search our forum and LibStock web site for some suggestions or examples:
www.libstock.com

Kind regards,
Aleksandar

PIC16F84A
Posts: 17
Joined: 18 Jun 2016 23:44

Re: PIC to PIC RF Communication Fails (PIC16F628A)

#6 Post by PIC16F84A » 02 Sep 2016 17:36

Thanks...
I tried lower baud rates but It didn't work...
I'm afraid I couldn't find any helpful information at libstock.com

MicroMark
Posts: 181
Joined: 11 Feb 2011 17:22

Re: PIC to PIC RF Communication Fails (PIC16F628A)

#7 Post by MicroMark » 02 Sep 2016 18:49

Usually when using simple RF modules, you want to use Manchester code format. There is a good
example in the compiler library.

Look up " Manchester Code Library" in the compiler help index

PIC16F84A
Posts: 17
Joined: 18 Jun 2016 23:44

Re: PIC to PIC RF Communication Fails (PIC16F628A)

#8 Post by PIC16F84A » 02 Sep 2016 22:06

I Will summarize the Last status:
When I run receiver circuit without running transmitter it Light on or off the Led.
It is weird...
When I run both of the circuits the Led doesn't Work stable...
It works, but although the led should Light on for 1 second and Light off for 1 second, It doesnt do That properly...
Sometimes it lit on for 500 ms
Sometimes 1.5 seconds,
Sometimes 1 second,
Sometimes etc... etc...
I think That I should use a encrypting system..
For example
I Will transmit "MIKROC_a" in order to transmit "a",
"MIKROC_b" in order to transmit "b".
The receiver Will wait for "MIKROC_" First
It Will process the next byte in order to avoid noises...


EDIT

The problem is solved...
Explanation is at the first message.

Post Reply

Return to “User Projects”