Chullaa
Advanced Member level 4
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
SLAVE
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';
}