Ram Prasadh
Member level 2
![Member level 2](/styles/images/ranks/dlevel2.gif)
Hi ,
I am presently trying out an SPI between MAXQ3180 and a pic16F72. I have written a code for just reading a register in MAXQ3180.But I am not able to get it in the master,PIC16F72.I am attaching the schematic which I have made and also the code which I have written for the communication. If anyone has worked with max,Please let me know if there is any mistake with the schematic or the program.
here goes the code
#include <htc.h>
#define IRQ RB0
#define buffer BF
#define SS RA5 //slave select pin ,active low
#define SCLK RC3
/*_ _ _ _ CONFIGURATIONS _ _ _ _ */
typedef unsigned int word;
word __at 0x2007 CONFIG = _HS_OSC & _WDT_OFF & _PWRTE_OFF & _CP_OFF & _BODEN_ON;
void MAX_MODULE();
void delay();
void check();
void check1();
void get_data_byte();
void switch_case();
void main(void)
{
ADCON1=0X06;
TRISC=0B00010010;
TRISA=0XFF;
TRISB=0X00;
PORTB=0X00;
SSPBUF=0;
SSPCON=0X32; //register used for initializing spi
SSPSTAT=0XC0;
MAX_MODULE();
SS=1;
delay();
for(;
;
}
void MAX_MODULE(void)
{
SS=0;
SSPBUF=0X00;
delay();
delay();
while(buffer==0);
buffer=0;
check();
SSPBUF=0X04;
delay();
delay();
while(buffer==0);
buffer=0;
check1();
get_data_byte();
}
void get_data_byte(void)
{
unsigned int a,b;
SSPBUF=0X00;
delay();
delay();
while(buffer==0);
buffer=0;
delay();
switch_case();
while(buffer==0);
buffer=0;
delay();
a=SSPBUF;
delay();
SSPBUF=0X00;
delay();
delay();
while(buffer==0);
buffer=0;
delay();
b=SSPBUF;
}
void switch_case(void)
{
unsigned int a;
a=SSPBUF;
switch(a)
{
case 0X4E:
delay();
SSPBUF=0X00;
delay();
while(buffer==0);
buffer=0;
delay();
switch_case();
break;
case 0X41:
delay();
SSPBUF=0X00;
delay();
break;
}
}
void check(void)
{
unsigned int a;
a=SSPBUF;
if(a==0XC1)
{
}
else
{
delay();
delay();
SSPBUF=0X00;
delay();
delay();
while(buffer==0);
buffer=0;
check()
}
}
void check1(void)
{
unsigned int d;
d=SSPBUF;
if(d==0XC2)
{
PORTB=d;
}
else
{
delay();
delay();
SSPBUF=0X00;
delay();
delay();
while(buffer==0);
buffer=0;
check1()
}
}
void delay(void)
{
unsigned int i,j,k;
for(i=0;i<255;i++)
for(j=0;j<255;j++)
for(k=0;k<20;k++);
}
I am presently trying out an SPI between MAXQ3180 and a pic16F72. I have written a code for just reading a register in MAXQ3180.But I am not able to get it in the master,PIC16F72.I am attaching the schematic which I have made and also the code which I have written for the communication. If anyone has worked with max,Please let me know if there is any mistake with the schematic or the program.
here goes the code
#include <htc.h>
#define IRQ RB0
#define buffer BF
#define SS RA5 //slave select pin ,active low
#define SCLK RC3
/*_ _ _ _ CONFIGURATIONS _ _ _ _ */
typedef unsigned int word;
word __at 0x2007 CONFIG = _HS_OSC & _WDT_OFF & _PWRTE_OFF & _CP_OFF & _BODEN_ON;
void MAX_MODULE();
void delay();
void check();
void check1();
void get_data_byte();
void switch_case();
void main(void)
{
ADCON1=0X06;
TRISC=0B00010010;
TRISA=0XFF;
TRISB=0X00;
PORTB=0X00;
SSPBUF=0;
SSPCON=0X32; //register used for initializing spi
SSPSTAT=0XC0;
MAX_MODULE();
SS=1;
delay();
for(;
}
void MAX_MODULE(void)
{
SS=0;
SSPBUF=0X00;
delay();
delay();
while(buffer==0);
buffer=0;
check();
SSPBUF=0X04;
delay();
delay();
while(buffer==0);
buffer=0;
check1();
get_data_byte();
}
void get_data_byte(void)
{
unsigned int a,b;
SSPBUF=0X00;
delay();
delay();
while(buffer==0);
buffer=0;
delay();
switch_case();
while(buffer==0);
buffer=0;
delay();
a=SSPBUF;
delay();
SSPBUF=0X00;
delay();
delay();
while(buffer==0);
buffer=0;
delay();
b=SSPBUF;
}
void switch_case(void)
{
unsigned int a;
a=SSPBUF;
switch(a)
{
case 0X4E:
delay();
SSPBUF=0X00;
delay();
while(buffer==0);
buffer=0;
delay();
switch_case();
break;
case 0X41:
delay();
SSPBUF=0X00;
delay();
break;
}
}
void check(void)
{
unsigned int a;
a=SSPBUF;
if(a==0XC1)
{
}
else
{
delay();
delay();
SSPBUF=0X00;
delay();
delay();
while(buffer==0);
buffer=0;
check()
}
}
void check1(void)
{
unsigned int d;
d=SSPBUF;
if(d==0XC2)
{
PORTB=d;
}
else
{
delay();
delay();
SSPBUF=0X00;
delay();
delay();
while(buffer==0);
buffer=0;
check1()
}
}
void delay(void)
{
unsigned int i,j,k;
for(i=0;i<255;i++)
for(j=0;j<255;j++)
for(k=0;k<20;k++);
}