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

bi-directional SPI with only one hardware port?

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



Joined: 17 Aug 2005
Posts: 19

View user's profile Send private message

bi-directional SPI with only one hardware port?
PostPosted: Tue Aug 01, 2006 12:52 pm     Reply with quote

I hope I haven't painted myself into a corner, but this could be something of a problem.

I have a PIC18F2420 with one hardware SPI port that needs to receive serial data, then transmit serial data to two other SPI devices. 99.9% of the time it won't be receiving and transmitting at the same time, but of course that is not reliable enough.

I have the SCK pin connected to the master device, as well as switched thru to the two slave devices controlled by the PIC using tri-state buffers triggered by the chip select lines.

The problem here is clock conflicts should the master device start clocking while the PIC happens to be talking to one of the two slave devices using the common clock line.

Do I need to create a software SPI port to avoid this potential clock conflict, or can I do something like using the SS pin to interrupt the PIC, stopping any SPI traffic currently being transmitted by the PIC (this is acceptable, corruption is not an issue). If the SS interrupt method is workable, is it "fast enough" to stop the transmitted clock and prevent conflicts? The PIC is running at 40 MHz, while the SPI master is transmitting data at a 200 KHz.

Thank you,
_________________
Lifespeed
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Aug 01, 2006 1:25 pm     Reply with quote

You have some low speed master device with a SPI clock running at
200 KHz. You didn't say, but this might be a PC that's toggling bits on
and off, on a parallel port.

The PC could connect to the hardware SPI pins on the 18F2420.
The SPI module on the 18F2420 would be configured as a slave device.

Then the 18F2420 could have a software SPI master port, which
connects to the other two PICs. Two pins on the 18F2420 could
act as Slave Select signals, one pin going to each PIC. The two
slave PICs would have their hardware SPI modules configured as
slaves.

The SPI clock rate for the PC is 200 KHz. You could easily run the
software SPI master code in the 18F2420 so that the software SPI
clock is 5 MHz. (Or even 1 MHz would be sufficient). You can disable
interrupts in the 18F2420 while you're transmitting a byte with the
software SPI port. Then re-enable them in-between bytes, so your
#INT_SSP interrupt (for the incoming byte from the PC) can be
serviced, if needed.
lifespeed



Joined: 17 Aug 2005
Posts: 19

View user's profile Send private message

PostPosted: Tue Aug 01, 2006 2:28 pm     Reply with quote

Thanks for your response.

The 200 KHz master is an old Motorola embedded CPU. I want to run a PID control algorithm on the PIC, with the control output being SPI writes to the DAC. The time frame for the controlled event is around 4 ms. A sample rate of 100X (a bit high, but a valid worst-case) is 40 microseconds between samples, with a worst case of a two-byte write every 40 us.

With a 5 MHz SPI clock, this would be 3.2 microseconds just to write to the DAC. I would prefer to use hardware SPI for output and leave the processor free for the PID control task.

Perhaps what you have suggested could be reversed, and I could run an interrupt-driven software SPI slave input?

Are you saying that using hardware input and output with the SS pin triggering the switch between In and Out is impossible? Or are you just suggesting an alternate method? I am not totally opposed to doing software SPI, but I'm wondering if bi-directional hardware SPI is even possible, given that the Master device can preempt the Slave devices without any problems resulting.
_________________
Lifespeed
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