Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

SPI COMMUNICATION Between two PIC (USING CCS)

Status
Not open for further replies.

Chullaa

Advanced Member level 4
Full Member level 1
Joined
Aug 27, 2010
Messages
113
Helped
17
Reputation
34
Reaction score
17
Trophy points
1,298
Activity points
2,019
Hi
How can we write code for SPI-SPI communication between two PICS. I have read codes but could not understand. Can i use SPI_Write function.

Here is my schematic.


MASTER
Code:
#include "C:\Users\home\Desktop\2PIC_SPI\Code\master\main.h"
void main()
{

   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_MASTER|SPI_L_TO_H|SPI_CLK_DIV_64);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   TRISD=0;
   PORTD=0;

   // TODO: USER CODE!!
   while(1)
   {
   PORTD=SSPBUF;
   while(!spi_data_is_in());
   }  
   
}


SLAVE
Code:
#include "C:\Users\home\Desktop\2PIC_SPI\Code\slave\main.h"

unsigned char value;
void main()
{

   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SLAVE);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   TRISD=0x00;
   PORTD=0x00;

   // TODO: USER CODE!!
   while(1)
   SSPBUF='A';
}
 



Code:
Master
////////////////////////////////////////////
unsigned int spi_write_hw(unsigned char val)
 {
    unsigned char ctrl;
    SS=0;
    SSPBUF=val;    while(!SSPIF);
    while(!BF);    ctrl=SSPBUF;
    SS=1;
    return ctrl; 
 }


Code:
slave
//////////////////////////////////
  void interrupt isr()
{
  if(SSPIF)
 {
   SSPIF=0;
   rcv=SSPBUF;  
   SSPBUF=snd;
 }
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top