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.

Is there anyone who has worked with maxq3180

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 communicating between a maxq3180 and a pic16f72. I have written a code for just reading a register in maxq3180 which uses spi for its communication. But I am not able to read the register in pic. I do not know where I make mistake. here is my code below


#include <htc.h>
#define buffer BF //BF IS A BIT IN SSPSTAT REGISTER IN PIC
#define SS RA5
void max_module();
void spi_read(int);
void get_data_byte();
void check_result();
void test_function();
void delay();
int send_data[3]={0X00,0X04,0x00};

void main(void)
{
ADCON1=0X06;
TRISA=0b00010000;
TRISB=0b00000001;
TRISC=0b00010001;
SSPBUF=0X00;
SSPCON=0X32; //register used for initializing spi
SSPSTAT=0XC0;
max_module();
// SS=1;
}

void max_module()
{
unsigned int i;
SS=0;
for(i=0;i<3;i++)
{
spi_read(send_data);
delay();
}
get_data_byte();

}

void spi_read(int a)
{

SSPBUF=a;
delay();
while(buffer==0);
buffer=0;
check_result();

}

void get_data_byte()
{
unsigned int c,d;
delay();
SSPBUF=0X00;
delay();
while(buffer==0);
buffer=0;
delay();
c=SSPBUF;
delay();
SSPBUF=0X00;
delay();
while(buffer==0);
buffer=0;
SS=1;
delay();
d=SSPBUF;
// PORTB=d;
delay();

}

void check_result()

{
unsigned int b;
b=SSPBUF;
if(b==0XC1)
{
PORTB=b;
delay();
}
else if(b==0XC2)
{
PORTB=b;
delay();
}
else if(b==0X4E)
{
PORTB=b;
delay();
SSPBUF=0X00;
delay();
while(buffer==0);
buffer=0;
b=SSPBUF;
check_result();
}
else if(b==0X41)


{
PORTB=b;
delay();
}
else
{
delay();
max_module();
}
}

void delay()
{
unsigned int l,j;
for(l=0;l<255;l++)
for(j=0;j<250;j++);
}



help me please....
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top