UART interface PIC to PIC problem

Discussion in 'Embedded Systems and Microcontrollers' started by rocker123uk, Jul 12, 2017.

  1. rocker123uk

    Thread Starter Member

    Dec 6, 2015
    33
    0
    Hi all,

    I am trying to interface pic to pic via uart. i have created code so that when the pushbutton is pressed, the pic would send signal to the other pic and turn the led but its not working. i have tried using the rf modules but i have heard that in order to make it easy. i must just connec the tx with the rx and its good to go.
    im using pic16f877a and programming on mikroc

    here is the transmitter code:

    Code (Text):
    1. void main() {
    2.      char txt = 'A';
    3.     TRISA.F0 = 1;
    4.     PORTA.F0 = 0;
    5.  
    6.     UART1_Init(2400);
    7.     Delay_ms(200);
    8.     while (1){
    9.     if(PORTA.F0 == 1){
    10.     delay_ms(100);
    11.     if (UART1_Tx_Idle() == 1) {
    12.      UART1_Write('A');
    13.     }
    14.     }
    15.    }
    16.  
    17.  
    18. }
    this is recieved code:

    Code (Text):
    1. void main() {
    2.      char output;
    3.     TRISB.F0 = 0;
    4.     PORTB.F0 = 0;
    5.  
    6.     UART1_Init(2400);
    7.     Delay_ms(200);
    8.     while (1){
    9.     if (UART1_Data_Ready() == 1) {          // if data is received
    10.      output = UART1_Read();
    11.     if (output == 'A'){
    12.                PORTB.F0 = 1;
    13.     }
    14.                                    }
    15.  
    16.     }
    17.  
    18. }
    Moderator edit: added code tags
     
  2. shteii01

    AAC Fanatic!

    Feb 19, 2010
    4,618
    730
    pic 1 tx connect to pic 2 rx
    pic 1 rx connected to pic 2 tx
     
  3. rocker123uk

    Thread Starter Member

    Dec 6, 2015
    33
    0
    i done that but it doesnt work? :(
     
  4. bertus

    Administrator

    Apr 5, 2008
    19,507
    3,972
    Hello,

    Are the ground connections also joined between pic1 and pic2?

    Bertus
     
  5. MaxHeadRoom

    Expert

    Jul 18, 2013
    17,903
    5,476
    Have you tested them coupled together? or is the distance to great?
    Oops I see you did in post 3?
    Max.
     
  6. rocker123uk

    Thread Starter Member

    Dec 6, 2015
    33
    0
    why would i ground pic1 with pic2 when im doing it wirelessly...i have set a distance between them approx 2metres and that doest help either
     
  7. bertus

    Administrator

    Apr 5, 2008
    19,507
    3,972
    Hello,

    I was responding on posts #2 and #3, as wired connection between the pics, so you can check the code.

    Bertus
     
  8. JohnInTX

    Moderator

    Jun 26, 2012
    3,620
    1,859
    As others have pointed out, you should try a direct connection first and get that working before you go on to RF links. If it does not work directly it won't work with the extra complexity of an RF module.

    Your code does not show that you have initialized ADCON1. That is necessary to be able to read RA0 as a digital input.
     
  9. rocker123uk

    Thread Starter Member

    Dec 6, 2015
    33
    0
    it is working directly so now im working with the rf modules but its just not working. do i have to put anything extra in the code for that to work? im using the following rf transmitter and reciever
    http://oap.sourceforge.net/datasheets/rf.pdf
     
  10. frankr21

    New Member

    Dec 16, 2016
    9
    1
    You should post your schematics of your circuits.
    Have you try to bring them closer to each other?
     
Loading...