Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC to PIC Synchronous transmission

Status
Not open for further replies.

tajiknomi

New Member
So i am working on Synchronous transmission of PIC16fxx to another PIC16fxx in proteus. One PIC act as a master and another as a slave.
Now when the IOC (interrupt on change) RB5 is active, the master will transfer the status of PORTA to Slave-Pic PORT-B.
Now the issue is, when i connect both the PIC MCU (shown in snapshot), the proteus below warns me the (Logic-Contention detect) & program doesn't execute on slave as expected.

I have read the datasheet but i am making some mistake which i don't see now. Kindly help me to determine where am i making a mistake.

Transmitter code (Master PIC)
Code:
char dummy = 0x00;
void interrupt(){

if (INTCON.RBIF == 1){                        // Change interrupt
           dummy = PORTA;         // MUST Read PORTB, otherwise flag will not clear
           TXREG = dummy;
           INTCON.RBIF = 0;
}

}
  void main()
  {
      TRISA = 0x0F;            // [RA0-RA3] = Inputs , PORTC = Output
      TRISB.f5 = 1;               // RA5 = Input (Used as IOC (interrupt on change))
      ADCON1 = 0x06;              // PORTA I/O as Digital I/O
      SPBRG = 0x67;               // decimal = 103, Baud-rate = 9600 , BRGH = 0
      TXSTA.CSRC=1; TXSTA.SYNC=1; TXSTA.TXEN=1; // Master clock from BRG, Synchronous mode, Transmission Enable
      RCSTA.SPEN=1;               // Enable Serial ports
      INTCON=0xC8;                // {Global interrupts , PORTB Change interrupt} = Enable

      while(1);
  }

Receiver Code
Code:
char dummy;
void interrupt(){

if (INTCON.RCIF == 1){           // Recieve interrupt

           dummy = RCREG;
           PORTB=dummy;
           INTCON.RCIF = 0;
}

}
  void main()
  {

      TRISB = 0x00; TRISC=0x03;   // PORTB = Output, PORTC [RC6-RC7] = Input
      //SPBRG = 0x67;               // decimal = 103, Baud-rate = 9600 , BRGH = 0
      TXSTA.CSRC=0; TXSTA.SYNC=1; // Slave clock from BRG, Enable Synchronous mode
      PIE1.RCIE=1;                // Recieve interrupt Enable
      RCSTA.SPEN=1;RCSTA.CREN=1;  // Enable Serial ports
      INTCON.GIE=1; INTCON.PEIE=1; // Global and Peripheral interrupts Enable
      PORTB = 0x00; PORTC=0x00;
      while(1);
  }

**broken link removed**

Thanks
 
Last edited:
You should connect the Transmitter TX to Receiver RX.
Now you have TX to TX connection.

Also, in the code you have a comment "// MUST Read PORTB, otherwise flag will not clear", but I don't see any code that reads portb.
 
Thanks for your kind reply,
Correct me if i am wrong, but i am using Synchronous transmission, means i will use DT & CK pin, CK will provide Clock to slave & DT will provide Data.
The slave device will receive byte through DT pin & Clock through CK.
 
Thanks for your kind reply,
Correct me if i am wrong, but i am using Synchronous transmission, means i will use DT & CK pin, CK will provide Clock to slave & DT will provide Data.
The slave device will receive byte through DT pin & Clock through CK.

Yes, ok.. I don't know then. From the code I had the expression that you are using serial port (TXREG and RCREG).. and in the comments you are stating "Enable Serial ports" and "Baud-rate = 9600".
If you are using serial port, then you need to connect TX to RX.
 
Last edited:
**broken link removed**
It seems like Slave-PIC is also making its pin (RC6 & RC7) as ouput. I don't know yet for sure.
P.S : Everything works fine until IOC occur, which cause the transmission to begin, then this "Logic contention" message appear
 
Connect the RX to TX .. just try it. Swap the connections in the slave PIC.
 
Connect the RX to TX .. just try it. Swap the connections in the slave PIC.

I've tried it, Its not working. Tx & Rx are only used in Asynchronous communication as far as i know. I am working on Synchronous protocol right now.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top