PDA

View Full Version : SPI Commands Operating Speed



gunayburak
- 4th November 2016, 18:26
Hello ;

Does anyone know the shiftin and shiftout commands clock speed and its dependency on the OSC or independency ?
Secondly ;

Do both slave and master have to be operating at the same OSC frequency in order to communicate via SPI protocol ?

Thanks in advance ..

HenrikOlsson
- 4th November 2016, 21:39
The manual says that the clock is roughly 50kHz and that it is dependent on the oscillator speed but it doesn't say how much. I guess you have an opportunity here to do some investigation and documentation and try it at a couple of different speeds and see what it does. Let us know.

No, the two devices does not need to run at the same oscillators speed. But, obviously, if you're using two PIC chips where the master is running at 64MHz and the slave a 4MHz it's possibly (or likely) that the SPI Clock(being generatd by the master) is too fast for the slave to keep up - but it depends on how much impact the oscillator speed actually has, so back to question 1.

/Henrik.

gunayburak
- 6th November 2016, 08:20
Thanks Henrik I'll give it a try .. :)

Art
- 9th November 2016, 16:04
You’ll get data in & out of the master faster than PBP if you express both the read and write routines in a verbose fashion such as below write routine.
It might need delays between pin writes that could be as short as @nop commands, and the routine is also a candidate for RWM error without adding
a shadow register for port latching (mind you, PBP SHIFTOUT command is probably no different). It’s probably faster again if the chip has hardware SPI.



byte data_out'

WriteSPI:
‘ bit 7
SPICLOCK = 0’
SPIOUT = 0’
SPICLOCK = 0’
SPIOUT = data_out.bit7’
SPICLOCK = 1’
‘ bit 6
SPICLOCK = 0’
SPIOUT = 0’
SPICLOCK = 0’
SPIOUT = data_out.bit6’
SPICLOCK = 1’

‘ and so on for the rest of the bits…

RETURN

HenrikOlsson
- 9th November 2016, 16:49
I just tried SHIFTOUT with 64MHz oscillator and the clock frequency is 300kHz. At the same speed the MSSP module would be able to spit out data Fosc/4 but then your code wouldn't be able to keep up with feeding the module so it won't be a sustained 16MHz bitrate.

/Henrik.

gunayburak
- 2nd December 2016, 11:26
Thanks for all the answers ..

I measured the SCK frequency 333 khz at 64 mhz so I wish pbp had a modification parameter for it (since we can't use all the pins for hardware SPI purpose)
Well , Maybe ART's suggestion may work .. as a subroutine .. Why not .. I'll try .. It shall be faster after all ..

Thanks once more to both of you

Art
- 4th December 2016, 00:56
It’s doesn’t “might” work, I play MP3s by using hardware SPI to read from SD card, and the above routine to write to the MP3 decoder.
Mind you, there are a few varieties of SPI you might have to experiment with (see the configuration of any pic with hardware SPI).