Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

SPI is not initiated between two PIC16F72.What might be the problem?

Status
Not open for further replies.

Ram Prasadh

Member level 2
Joined
Feb 16, 2011
Messages
51
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Activity points
1,725
Hi
I am Interfacing two PIC16F72 with SPI.I have programmed in PIC,but this is the first time I have tried SPI.I am attaching the code for both slave and the master. Please guide me with what mistake am doing. In the master mode I am just incrementing a count and am sending it to the port B in the slave mode.I checked with a multimeter in the slave ic. I am not getting any change there.
Help me Please......HELP ME FIND MY MISTAKE.

/*_ _ _ _ SPI MASTER MODULE_ _ _ _*/



#include<htc.h>
#define SS PORTAbits.RA5 //SLAVE SELECT IN PORTA 5
typedef unsigned int word;
word __at 0x2007 CONFIG = _HS_OSC & _WDT_OFF & _PWRTE_OFF & _CP_OFF & _BODEN_ON;
void initialize();
void sspmodule();
void delay();

void main(void)
{
while(1)
{
unsigned char count,a,b;
initialize();
sspmodule();
delay();
}
}
void initialize()
{

SSPCON=0X31; //SYNCHRONOUS SERIAL PORT CONTROL REGISTER
SSPSTAT=0XC0;//SYNCHRONOUS SERIAL PORT STATUS REGISTER
SSPBUF=0X00; //SYNCHRONOUS SERIAL PORT BUFFER REGISTER
TRISC=0X10; //SDO OUTPUT,SCK OUTPUT,SDI INPUT
TRISA=0X00;
ADCON1=0X06;
INTCON=0XC0;
PIE1=0X09;
count=0;
count=count+1;
}


void sspmodule()
{

SS=0;
SSPBUF=count;
delay();
}


void delay()

{

for(a=0;a<100;a++)
for(b=0;b<255;b++)
}



/*_ _ _ _ SLAVE MODULE_ _ _ _*/

#include<htc.h>
#define SS PORTAbits.RA5 //slave select bit is assigned to porta 5th pin
typedef unsigned int word;
word __at 0x2007 CONFIG = _HS_OSC & _WDT_OFF & _PWRTE_OFF & _CP_OFF & _BODEN_ON;


void main(void)
{

while(1)
{
unsigned char a,b;
initialize();
recieve();
//display();
delay();
}
}

void initialize()

{
SSPCON=0X34;
SSPSTAT=0X40;
TRISC=0X18;
TRISA=0X00;
ADCON1=0X06;
SS=1;
TRISB=0X00;
}

void recieve()

{

while(SSPSTATbits.BF==0);
a=SSPBUF;
PORTB=a;
delay();
}

void delay()

{

unsigned char a,b;
for(a=0;a<100;a++)
for(b=0;b<200;b++)
}
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top