SPI Commands Operating Speed


+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Dec 2012
    Location
    Türkiye
    Posts
    103

    Default SPI Commands Operating Speed

    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 ..
    - Ipsa scientia potestas est -

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,373

    Default Re: SPI Commands Operating Speed

    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.

  3. #3
    Join Date
    Dec 2012
    Location
    Türkiye
    Posts
    103

    Default Re: SPI Commands Operating Speed

    Thanks Henrik I'll give it a try ..
    - Ipsa scientia potestas est -

  4. #4
    Join Date
    Aug 2003
    Location
    Australia
    Posts
    984

    Default Re: SPI Commands Operating Speed

    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.

    Code:
    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
    Last edited by Art; - 9th November 2016 at 17:06.

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,373

    Default Re: SPI Commands Operating Speed

    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.

  6. #6
    Join Date
    Dec 2012
    Location
    Türkiye
    Posts
    103

    Default Re: SPI Commands Operating Speed

    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
    - Ipsa scientia potestas est -

  7. #7
    Join Date
    Aug 2003
    Location
    Australia
    Posts
    984

    Default Re: SPI Commands Operating Speed

    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).

Similar Threads

  1. Any gotcha's when operating at 32KHz
    By caseyc in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 14th November 2008, 14:20
  2. Replies: 0
    Last Post: - 7th August 2008, 10:02
  3. Operating system kernels for microcontrollers!??!
    By Armando Herjim in forum General
    Replies: 2
    Last Post: - 3rd October 2006, 22:47
  4. SPI on a pic without hardware SPI?
    By modifyit in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 26th April 2006, 14:29
  5. Operating a PIC at 3V ?
    By Scott in forum Off Topic
    Replies: 5
    Last Post: - 12th September 2005, 00:59

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts