View previous topic :: View next topic |
Author |
Message |
temopic
Joined: 20 Feb 2008 Posts: 27 Location: mexico
|
SPI ----1 Pic Master / Multiple Pic Slaves |
Posted: Sun Mar 16, 2008 1:19 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
Re: SPI ----1 Pic Master / Multiple Pic Slaves |
Posted: Sun Mar 16, 2008 3:21 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
temopic
Joined: 20 Feb 2008 Posts: 27 Location: mexico
|
|
Posted: Sun Mar 16, 2008 6:34 pm |
|
|
Done that way on purpose Neutone,
Any idea why they (SDO) arent in hig-Z if /SS is active high? |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Mar 16, 2008 8:17 pm |
|
|
Post the setup_spi() statement for your Slave PICs. |
|
![](templates/subSilver/images/spacer.gif) |
temopic
Joined: 20 Feb 2008 Posts: 27 Location: mexico
|
|
Posted: Mon Mar 17, 2008 8:08 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
temopic
Joined: 20 Feb 2008 Posts: 27 Location: mexico
|
|
Posted: Mon Mar 17, 2008 8:53 am |
|
|
.................... 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? |
|
![](templates/subSilver/images/spacer.gif) |
temopic
Joined: 20 Feb 2008 Posts: 27 Location: mexico
|
|
Posted: Mon Mar 17, 2008 9:04 am |
|
|
#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 |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Mar 17, 2008 2:52 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
|