UART interface PIC to PIC problem

Thread Starter

rocker123uk

Joined Dec 6, 2015
33
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:
void main() {
     char txt = 'A';
    TRISA.F0 = 1;
    PORTA.F0 = 0;
  
    UART1_Init(2400);
    Delay_ms(200);
    while (1){
    if(PORTA.F0 == 1){
    delay_ms(100);
    if (UART1_Tx_Idle() == 1) {
     UART1_Write('A');
    }
    }
   }


}
this is recieved code:

Code:
void main() {
     char output;
    TRISB.F0 = 0;
    PORTB.F0 = 0;

    UART1_Init(2400);
    Delay_ms(200);
    while (1){
    if (UART1_Data_Ready() == 1) {          // if data is received
     output = UART1_Read();
    if (output == 'A'){
               PORTB.F0 = 1;
    }
                                   }

    }

}
Moderator edit: added code tags
 

Thread Starter

rocker123uk

Joined Dec 6, 2015
33
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
 

bertus

Joined Apr 5, 2008
22,882
Hello,

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

Bertus
 

JohnInTX

Joined Jun 26, 2012
4,787
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
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.
 
Top