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 CCS Technical Support

SPI ----1 Pic Master / Multiple Pic Slaves

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
temopic



Joined: 20 Feb 2008
Posts: 27
Location: mexico

View user's profile Send private message MSN Messenger

SPI ----1 Pic Master / Multiple Pic Slaves
PostPosted: Sun Mar 16, 2008 1:19 pm     Reply with quote

I am using PCW 4.065, Mplab 7.6 and PIC18F2520

I have a PCB with 1 Master and 8 Slaves (All PIC18F2520).

I can send and receive data from the Master to a Slave if and only if one Slave is in the PCB board. If I insert another Slave the Master continue to be able to send to the selected Slave correctly but cant read from it in the Master.

I am using in the Master pin_a0, a1, a2 a3 with a MM74HC138 3-to-8 Line Decoder and select only one Slave at the time (in their pin_a5).

The master has-------connected to--------The slave ----------
RC5--(SDO)------------------------------------RC4--(SDI)
RC4--(SDI)-------------------------------------RC5--(SDO)
RC3--(CLK)-------------------------------------RC3--(CLK)
MM74HC138 3-to-8 Line Decoder-------------RA5--(SS)

I did remove the RC5 (SDO) from 2 inserted Slaves into the PCB and select one or the other Slave (RA5 SS) to see if high-Z for Slave's SDO but always remain in LOW, i believe it should be un high-Z if SS is High.
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

Re: SPI ----1 Pic Master / Multiple Pic Slaves
PostPosted: Sun Mar 16, 2008 3:21 pm     Reply with quote

temopic wrote:
I am using PCW 4.065, Mplab 7.6 and PIC18F2520

I have a PCB with 1 Master and 8 Slaves (All PIC18F2520).

I can send and receive data from the Master to a Slave if and only if one Slave is in the PCB board. If I insert another Slave the Master continue to be able to send to the selected Slave correctly but cant read from it in the Master.

I am using in the Master pin_a0, a1, a2 a3 with a MM74HC138 3-to-8 Line Decoder and select only one Slave at the time (in their pin_a5).

The master has-------connected to--------The slave ----------
RC5--(SDO)------------------------------------RC4--(SDI)
RC4--(SDI)-------------------------------------RC5--(SDO)
RC3--(CLK)-------------------------------------RC3--(CLK)
MM74HC138 3-to-8 Line Decoder-------------RA5--(SS)

I did remove the RC5 (SDO) from 2 inserted Slaves into the PCB and select one or the other Slave (RA5 SS) to see if high-Z for Slave's SDO but always remain in LOW, i believe it should be un high-Z if SS is High.

The SS is negative logic. There is a bar over SS. Keep all SS high until selected. Fortunately the 74HC138 should drive all outputs high except one if it is enabled. Otherwise all outputs will be high.
temopic



Joined: 20 Feb 2008
Posts: 27
Location: mexico

View user's profile Send private message MSN Messenger

PostPosted: Sun Mar 16, 2008 6:34 pm     Reply with quote

Done that way on purpose Neutone,

Any idea why they (SDO) arent in hig-Z if /SS is active high?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Mar 16, 2008 8:17 pm     Reply with quote

Post the setup_spi() statement for your Slave PICs.
temopic



Joined: 20 Feb 2008
Posts: 27
Location: mexico

View user's profile Send private message MSN Messenger

PostPosted: Mon Mar 17, 2008 8:08 am     Reply with quote

setup_spi(spi_slave | spi_L_to_H);


I am reading that /SS Control should be enabled.

I already try:

setup_spi(spi_slave | spi_L_to_H | ss_enabled);

But cant compile it :-s
temopic



Joined: 20 Feb 2008
Posts: 27
Location: mexico

View user's profile Send private message MSN Messenger

PostPosted: Mon Mar 17, 2008 8:53 am     Reply with quote

.................... setup_spi(spi_slave | spi_L_to_H);
03DE: BCF FC6.5
03E0: BCF F94.5
03E2: BSF F94.4
03E4: BSF F92.5
03E6: BSF F94.3
03E8: MOVLW 24 ----------------Set SSPEN and [0100 SPI Slave mode, clock = SCK pin, SS pin control enabled]
03EA: MOVWF FC6
03EC: MOVLW 00
03EE: MOVWF FC7

So why is not giving me a tri-state output when /SS is high?
temopic



Joined: 20 Feb 2008
Posts: 27
Location: mexico

View user's profile Send private message MSN Messenger

PostPosted: Mon Mar 17, 2008 9:04 am     Reply with quote

#bit SSPCON1_0 = 0xFC6.0
#bit SSPCON1_1 = 0xFC6.1
#bit SSPCON1_2 = 0xFC6.2
#bit SSPCON1_3 = 0xFC6.3

After a debug read:

SSPCON1_0 =0
SSPCON1_1 =0
SSPCON1_2 =1
SSPCON1_3 =0
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Mar 17, 2008 2:52 pm     Reply with quote

Post a small test program for the SPI slave that shows the problem.

Make sure you post all the #include, #fuses, #use delay() and other
#use statements. The program must be compilable without errors.
Make it as short as possible. For example, here is my idea of a short
program:
Code:

#include <18F2520.h>
#fuses XT,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=4000000)

//====================================
void main()
{
setup_spi(SPI_SLAVE | SPI_L_TO_H);

while(1);
}


Create your short test program. Run it, and do some tests that prove
that the SDO pin is still active even though the \SS pin is high. Tell us
what the test procedure was.

For example, I made a program similar to the one above, except it was
for an 18F452 (I don't have an 18F2520). I connected the \SS pin to
a 4.7K pullup resistor, so it was held at a high level. Then I put a scope
probe on the SDO pin. I attached a wire to the SDO pin and touched it
with my finger. I saw AC "hum" on it, which means that it's floating.
I then attached a 10K resistor to the wire, and touched the end to +5v
and then to Ground. I saw on the scope that the SDO signal went high
and then low. So the SDO pin was definitely floating when the \SS pin
was high.

Then I jumpered the \SS pin to ground. The SDO pin went to a high
level. It did not have AC "hum" on it. When I connected a 10K resistor
between the SDO pin and ground, the SDO pin stayed at a high level.
This means that when the \SS pin is held low, the SDO pin is driven by
the PIC. So it's all working correctly. The little test program shown
above allowed me to prove this.

You should do a similar test with the 18F2520.
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