CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

SPI works with 1 slave but not with 5

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
topfuel@frognet.net



Joined: 30 Nov 2008
Posts: 5

View user's profile Send private message Send e-mail

SPI works with 1 slave but not with 5
PostPosted: Wed Apr 15, 2009 7:06 pm     Reply with quote

I have an applicaiton that uses an SPI master 18F4685 and 5 SPI slaves 18F2523.

I have the master and 1 slave working. I add the other pcb to the spi bus, this board has the 4 other pics that are on the spi bus. Now when I restart the first slave no longer responds correctly.

I suspected that i had multiple pics selected on the spi bus . I have a simple 138 decoder to select the active slave pic.

The decoder seems to be working. I run the master code in debug and the slave select decoder is working correctly on slave 1-5.

I connected my scope to the sclk line and I can see the clock pulses but I notice that my project will not communicate while the scope is connected. Also I have no buffering between the mater pic and the 5 slaves. Should I?

Why does the scope kill my comm? The signal looks very clean on the scope, no rounded edges. Crystal is 16.384Mhz and spi is set to clk/64.

Tomorrow I will debug both master and slave at the same time to hopefully get a better idea what is going on.

Any suggestions?

Chris
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Apr 15, 2009 7:47 pm     Reply with quote

Buffering between master and slaves is normally not required. What is the wire length between master and slaves?

The scope can be loading the SCK line too much. Make sure to use an x10 probe.

Check out http://www.ccsinfo.com/forum/viewtopic.php?t=21650&start=10 this thread where a series resistor of 100 Ohm in the SCK line solved a similar problem.
topfuel@frognet.net



Joined: 30 Nov 2008
Posts: 5

View user's profile Send private message Send e-mail

Thank You Mark at CCS
PostPosted: Sun Apr 19, 2009 7:04 pm     Reply with quote

I called Mark at CCS after several hours of troubleshooting.

Here is the culprit.

setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_16 | SPI_XMIT_L_TO_H );

I was not aware of the SPI_XMIT_L_TO_H .

I just had

setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_16 );

My slave was the same situation.

Thank You Mark!!!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Apr 19, 2009 7:08 pm     Reply with quote

You have changed it from using SPI Mode 1, to Mode 0. Here are
the #define statements for the modes:
Code:
#define SPI_MODE_0  (SPI_L_TO_H | SPI_XMIT_L_TO_H)
#define SPI_MODE_1  (SPI_L_TO_H)
#define SPI_MODE_2  (SPI_H_TO_L)
#define SPI_MODE_3  (SPI_H_TO_L | SPI_XMIT_L_TO_H)
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon Apr 20, 2009 2:04 am     Reply with quote

And as extra info: Master and Slave must have the same SPI mode setting.

What I don't understand is that how changing the SPI mode did solve your problem. As long as you had the Master and all Slaves configured for the same mode then your change can not have solved the underlying problem.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group