News:

Let's find out together what makes a PIC Tick!

Main Menu

SPI clock frequency in Positron 16

Started by Wimax, Oct 09, 2021, 02:16 PM

Previous topic - Next topic

Wimax

Finally it works  ;D ! A small bug in the program, in the data reading routine. There are 7 cycles with a left shift command and the last, with the LSB, without.

'-----------------------------------------------------------------------------
' Read an 8-bit value using the SPI mode 0 protocol (MSB first)
' Input    : None
' Output    : Returns the 8-bit value received
' Notes    : SCK is idle-low, and bits are latched on SCK rising
'
Proc SPI_Mode0_Read8(), Byte
    Dim bLoop As Byte
    PinClear SPI_SCK_Pin                        ' Make sure the CLK pin is low before the loop starts
    PinSet SPI_MOSI_Pin                        ' Set the MOSI pin
        For bLoop = 7 To 1 Step -1                  ' Single byte SPI loop
        PinSet SPI_SCK_Pin                      ' Set the SCK pin high
        DelayCS cSPI_Delay                      ' A delay between the clock cycles
        Result.0 = SPI_MISO_Pin                ' Capture the current bit on MISO
        Result = Result << 1                    ' Shift left for MSB first
        PinClear SPI_SCK_Pin                    ' Set the SCK pin low
        DelayCS cSPI_Delay                      ' A delay between the clock cycles
        Next
        ' Now there is the LSB left that hasn't to be shifted
        PinSet SPI_SCK_Pin                      ' Set the SCK pin high
        DelayCS cSPI_Delay                      ' A delay between the clock cycles
        Result.0 = SPI_MISO_Pin                ' Capture the current bit on MISO
        PinClear SPI_SCK_Pin                    ' Set the SCK pin low
        DelayCS cSPI_Delay                      ' A delay between the clock cycles
     
EndProc

Running the little monster @ 79 MHz and setting DelayCS=2 --> 10 MB in about 30 seconds, the transfer rate is near 2.7 Mb/s (the calculation is not accurate as it is done by hand). I think it's not bad at all for a breadboard mounted RAM  :) !