Clock frequency in SPI communication


+ Reply to Thread
Results 1 to 12 of 12

Thread: Clock frequency in SPI communication94 days old

  1. #1
    Member teo's Avatar
    Join Date
    Sep 2010
    Posts
    348
    Thumbs Up
    Received: 10
    Given: 1
    Total Downloaded
    7.88 GB

    0 Not allowed!

    Default Clock frequency in SPI communication

    Hello everybody,
    How can I set the clock frequency in SPI communication to 248 bps?
    Thanks in advance,
    Teo

  2. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  3. #2
    Fanatical Contributor Tim's Avatar
    Join Date
    Jan 2003
    Posts
    7,818
    Thumbs Up
    Received: 52
    Given: 96
    Total Downloaded
    1.35 GB

    0 Not allowed!

    Default Re: Clock frequency in SPI communication

    Really its just roll your own

    Most of my code uses hand coded spi so its just a change in delays

    I can post one if it helps
    Tim

  4. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  5. #3
    Member teo's Avatar
    Join Date
    Sep 2010
    Posts
    348
    Thumbs Up
    Received: 10
    Given: 1
    Total Downloaded
    7.88 GB

    0 Not allowed!

    Default Re: Clock frequency in SPI communication

    Hi Tim,
    Thanks for the reply.
    I have to encode 22 bits in Biphase Mark Code and I was thinking of generating SPI Clock and DATA signals. Then with the help of external circuits to transform the two signals into a single BMC signal. If you can post a code for SPI with Low Frequency it would be great.
    Thanks in advance,
    Teo

  6. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  7. #4
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    2,373
    Thumbs Up
    Received: 87
    Given: 183
    Total Downloaded
    5.30 GB

    0 Not allowed!

    Default Re: Clock frequency in SPI communication

    Of course if you use the MSSP directly you have many selectable clock sources but I doubt if you can go that slow. Anyway I see your using 22 bit so forget my post.
    George.

  8. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  9. #5
    Member teo's Avatar
    Join Date
    Sep 2010
    Posts
    348
    Thumbs Up
    Received: 10
    Given: 1
    Total Downloaded
    7.88 GB

    0 Not allowed!

    Default Re: Clock frequency in SPI communication

    Hi George,
    Thanks for the reply.
    Teo

  10. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  11. #6
    Fanatical Contributor Tim's Avatar
    Join Date
    Jan 2003
    Posts
    7,818
    Thumbs Up
    Received: 52
    Given: 96
    Total Downloaded
    1.35 GB

    0 Not allowed!

    Default Re: Clock frequency in SPI communication

    Code:
        Dim MISO_Pin As GPIO.3                                 ' Connects to                     
        Dim MOSI_Pin As GPIO.2                                 ' Connects to                     
        
        Dim MOSI_Tris As TRISIO.2
        Dim SCLK_Pin As GPIO.1
        Dim SCLK_Tris As TRISIO.1                                                    
    
    
        $define SPI_OutLow  Low MOSI_Pin
        $define SPI_OutHigh  MOSI_Tris = 1
        $define SPI_ClkLow   Low  SCLK_Pin
        $define SPI_ClkHigh   SCLK_Tris = 1  
    
    
        Proc SPI_RWrite(_Byteout As Byte), Byte
            Dim bSPITemp As Byte
            Dim bSpiIndex As Byte
        
            bSPITemp = _Byteout                                 ' Transfer the data into _bSPI_Data
            bSpiIndex = 0
            Repeat                                              ' Single byte SPI loop                    
                SPI_ClkLow                                      ' Set SCLK low
                SPIDelay 
                If bSPITemp.7 = 0 Then
                    SPI_OutLow
                Else
                    SPI_OutHigh
                EndIf
                bSPITemp = bSPITemp << 1                        ' Shift next bit into MSB
                SPIDelay
                SPI_ClkHigh                                     ' let SCLK float high
                bSPITemp = bSPITemp | MISO_Pin                  ' Capture current bit on MOSI_Pin
                Inc bSpiIndex
            Until bSpiIndex >=8                
            PostSPI_Delay
            
            Result =  bSPITemp                                   ' Transfer bSPI_Data into WREG
            
        EndProc
    
    
        $define InterSPIDelay DelayUS 3
    Tim

  12. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  13. #7
    Member teo's Avatar
    Join Date
    Sep 2010
    Posts
    348
    Thumbs Up
    Received: 10
    Given: 1
    Total Downloaded
    7.88 GB

    0 Not allowed!

    Default Re: Clock frequency in SPI communication

    Hi Tim,
    Thank you very much
    Teo

  14. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  15. #8
    Member teo's Avatar
    Join Date
    Sep 2010
    Posts
    348
    Thumbs Up
    Received: 10
    Given: 1
    Total Downloaded
    7.88 GB

    0 Not allowed!

    Default Re: Clock frequency in SPI communication

    Hi Tim,
    Please help me, if you have some time, with "Proc SPI_Read (_Bytein As Byte), Byte"
    Thank you in advance,
    Teo

  16. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  17. #9
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,691
    Thumbs Up
    Received: 357
    Given: 173
    Total Downloaded
    2.02 GB

    0 Not allowed!

    Default Re: Clock frequency in SPI communication

    With SPI, you will need to know what mode it is using.

    The mode indicates where the data is transferred on the clock cycle and what the resting clock should be. i.e. high or low. It also has to be knowen if the data is sent/received MSB or LSB. There are, generally, 4 modes of SPI, but also some more unique types.

    Without the mode type being followed, the SPI interface will not work.

    Here's a Mode 0 SPI 16-bit write and read procedure that I've used in several projects.

    Code:
    '-----------------------------------------------------------------------------------
    ' Read and Write 16-bits on an SPI interface
    ' Input     : pValue holds the 16-bits to write to the SPI interface
    ' Output    : Returns 16-bits read from the SPI interface
    ' Notes     : MSBFIRST, SPI_MODE0
    '
    Proc SPI_Transfer16(pValue As Word), Word
        Dim bLoop As Byte
    
        Low SPI_CLK_Pin                     ' Start with the CLK pin low
        Output SPI_MOSI_Pin
        Input SPI_MISO_Pin
        For bLoop = 15 To 0 Step -1         ' Create a loop for the 16-bits
            SPI_MOSI_Pin = pValue.15        ' Set the MOSI pin to the value held in a bit of pValue
            pValue = pValue << 1            ' Rotate the out bits left
            Result = Result << 1            ' Rotate the in bits left
            Set SPI_CLK_Pin                 ' Make the CLK pin high
            DelayCS 2                       ' A small delay between clock cycles
            Result.0 = SPI_MISO_Pin         ' Read the MISO pin's state
            Clear SPI_CLK_Pin               ' Make the CLK pin low
        Next
    EndProc
    In order to use SPI, you should do some research on it, otherwise when things do not work you will not know where to look. It's one of the more simple and reliable serial interface mechanisms, so the reasearch will not be complex.

    MOSI and MISO pins designate "Master Out Slave In" or "Master In Slave Out" MOSI is the input on the slave device and the output from the master devcce, and MISO is the output from the slave device and the input on the master device.
    Last edited by top204; 15th May 2020 at 14:00.

  18. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  19. #10
    Member teo's Avatar
    Join Date
    Sep 2010
    Posts
    348
    Thumbs Up
    Received: 10
    Given: 1
    Total Downloaded
    7.88 GB

    0 Not allowed!

    Default Re: Clock frequency in SPI communication

    Hi Les,
    Thanks for the reply.
    I have to encode 22 bits in Biphase Mark Code and I was thinking of generating SPI Clock and DATA signals. Then with the help of external circuits to transform the two signals into a single BMC signal.
    Thanks in advance,
    Teo

  20. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  21. #11
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,691
    Thumbs Up
    Received: 357
    Given: 173
    Total Downloaded
    2.02 GB

    0 Not allowed!

    Default Re: Clock frequency in SPI communication

    In the compiler's "Samples\Proteus" directory, there is a manchester Encoder/Decoder program that I wrote many, many years ago. "Manchester.bas"

    The Manchester code is a Bi-Phase type and the program could be adapted for any device type and as many bits required by altering the Repeat-Until loop iterations. It may help you, and it could easily be made into Send and Receive procedures.

  22. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  23. #12
    Member teo's Avatar
    Join Date
    Sep 2010
    Posts
    348
    Thumbs Up
    Received: 10
    Given: 1
    Total Downloaded
    7.88 GB

    0 Not allowed!

    Default Re: Clock frequency in SPI communication

    Hi Les,
    Thank you very much
    Teo


  24. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. 18F25K20 osc / clock odd frequency
    By brett in forum Proton Plus Compiler v3
    Replies: 10
    Last Post: 28th November 2019, 14:29
  2. I2c, SPI, RS-232 (TTL) Communication
    By myeeplacee in forum Proton Plus Compiler v3
    Replies: 7
    Last Post: 25th March 2014, 22:54
  3. [SOLVED !] how to disable processor clock frequency in proteus
    By s4cnc in forum Labcenter Proteus VSM
    Replies: 3
    Last Post: 5th April 2009, 13:30
  4. [SOLVED !] SPI clock rate
    By all77 in forum Proton Plus Compiler v3
    Replies: 1
    Last Post: 26th September 2007, 14:04
  5. VSM 16F877 clock frequency
    By Alan in forum Labcenter Proteus VSM
    Replies: 7
    Last Post: 26th February 2006, 08:04

Posting Permissions

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