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.

16f877a SPI slave read problem

Status
Not open for further replies.

sresam89

Member level 2
Joined
Sep 9, 2009
Messages
48
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,576
hi all
i am trying to implement spi communication between two 16f877a.
am giving my CCS code below

Code:
for master
void main()
{
TRISC=0x10;//SCK is output (Master), SDI is input,
TRISA=0x00;//Slave Select Bit
ADCON1=0x06;
SSPSTAT=0x40;//Mode 1,1 SPI, middle of output time sampling
SSPCON=0x31;//Mode 1,1 SPI Master, 1/16 Tosc bit, SSP is on
SSPIF=0;
WCOL=0;
SSPBUF=0;
lcd_init();
do{
i=0;
ss=0;//also tried always tying Slave SS pin to gnd instead of switching
lcd_putc("\fDATA TRANSMIT\n");delay_ms(2000);
while(wcol);
SSPBUF='b';
while(!SSPIF);
SSPIF=0;
ss=1;//also tried always tying Slave SS pin to gnd  instead of switching
printf(lcd_putc,"\fDATA done:1 %C",SSPBUF); delay_ms(3000);
ss=0;//also tried always tying Slave SS pin to gnd  instead of switching
lcd_putc("\fDATA TRANSMIT\n");delay_ms(2000);
while(wcol);
SSPBUF='a';
while(!SSPIF);
SSPIF=0;
ss=1;//also tried always tying Slave SS pin to gnd  instead of switching
lcd_putc("\fDATA done:2"); delay_ms(3000);
}while(1);
}


the code is fine and is transmitting perfectly. checked using proteus.also verified using some hard way(mentioned later).

Code:
for salve
void main()
{
int8 i=0;
TRISC=0x18;//SCK is input (Slave), SDI is input,SDO is output, all others output
TRISA=0X10;//SLAVE Select Bit
ADCON1=0x06;
SSPSTAT=0x40;//Mode 1,1 SPI, middle of output time sampling
SSPCON=0x34;//SPI Slave Mode(SS bit controlled), 1/16 Tosc bit, SSP is on
SSPBUF=0;
SSPIF=0;
lcd_init();
while(1){
lcd_putc("\fwaiting");
while((BF==0));
SSPIF=0;
printf(lcd_putc," :%c",SSPBUF);
lcd_putc("\ndata");DELAY_MS(500);
}
}

this receiver is receiving initially(soon after reset at any point of time) a single character only and halts indefinitely at "waiting" for SSPIF(also tried switching it to BF). the transmitter is sending all the characters mentioned in the program(verified using reset @ slave Before every Tx from Master)
 

hi

first try it in single word is transmitted to slave ?& vice versa.
 

solved the slave issue by changing the value of SSPCON @ slave code to 0x35
 

solved the slave issue by changing the value of SSPCON @ slave code to 0x35
hello all.
i have a small query...
i know writing 0x35 to SSPCON ll control the salve using SlaveSelect pin @ PA.5, also the salve pin need to be controlled by the master by pulling it to ground to select the slave. All good till now..
the query is..
1.is it so that the SS pin be toggled after/before every 8-bit Data reception? (i found it working only so). permanent grounding dint work.
2.connecting the SS pin of slave(PA.5) directly to any port-pin of master to select it also din work out. either i need to use a transistor to switch it or do it manually!. Why was this happening.

though i have not put the code for my query i hope someone could help, with one posted.
 

ok parthiban finally digged out the link. but i couldn find any solution for my problem. or are you asking for help?

did you got the solution for your problem?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top