thomasn101 Guest
|
Fastest SW SPI code |
Posted: Tue Feb 24, 2004 2:26 pm |
|
|
Hi everyone,
I want to speed up my software SPI code. With the crystal freq at 20Mhz, the transfer rate of the code below is about 270Khz. Is there anything I can do to speed it up?
Regards,
Thomas
Code: |
int SW_SPI_TXRX(int dataout)
{
int Spi_Bit_Count, Datain;
#Asm
Bcf Porte, 0 // Clock Low
Clrf Spi_Bit_Count
Next_Bit:
Bcf Porte, 1 // Clear Data_Out Pin
Rlf Dataout, F
Btfsc Status, 0
Bsf Porte, 1 // Set Data_Out Pin
Bsf Porte, 0 // Clock High
Bcf Porte, 0 // Clock Low
Bcf Status, 0 // Clear C
Btfsc Portd, 3 // Check Data_In Pin
Bsf Status, 0 // Set C
Rlf Datain, F
Incf Spi_Bit_Count, F
Movlw 8
Subwf Spi_Bit_Count,W
Btfss Status, 2 // Check Status, Z Flag
Goto Next_Bit
Movf Datain, W
Movwf _Return_
#Endasm
}
|
|
|