Hi,
This subroutine happily bit-bangs SPI (sending a byte) for an RTC and a radio:
this version, however, which I unrolled (a) for speed and (b) to avoid trashing two registers, does not, and appears to always send a $00:
I can point you to complete sources files on SourceForge if that would help!
Note the swerve already for SPI_SDO and SPI_SDO_PIN.
Any ideas?
Rgds
Damon
This subroutine happily bit-bangs SPI (sending a byte) for an RTC and a radio:
Code:
SPI shift out (ie write) a single byte, most-significant bit first, data pre-clock.
; Sends output data from SPI_DATAB byte variable.
; Destroys tempB0, tempB1, SPI_DATAB.
SPI_shiftout_byte_MSB_preclock:
for tempB0 = 0 to 7
tempB1 = SPI_DATAB & $80
if tempB1 = 0 then
low SPI_SDO
else
high SPI_SDO
end if
pulsout SPI_SCLK_O, 1 ; pulse clock for 10us to send next bit
SPI_DATAB = SPI_DATAB + SPI_DATAB
next tempB0
return
Code:
;FAILED OPTIMISATION: SEEMS TO ALWAYS BEHAVE AS IF SPI_DATAB == 0.
; SPI shift out (ie write) a single byte, most-significant bit first, data pre-clock.
; Sends output data from SPI_DATAB byte variable.
; Destroys B0.
; Unrolled for speed and to reduce the working memory required: a few bytes larger than loop version...
SPI_shiftout_byte_MSB_preclock:
B0 = SPI_DATAB
SPI_SDO_PIN = bit7
pulsout SPI_SCLK_O, 1
SPI_SDO_PIN = bit6
pulsout SPI_SCLK_O, 1
SPI_SDO_PIN = bit5
pulsout SPI_SCLK_O, 1
SPI_SDO_PIN = bit4
pulsout SPI_SCLK_O, 1
SPI_SDO_PIN = bit3
pulsout SPI_SCLK_O, 1
SPI_SDO_PIN = bit2
pulsout SPI_SCLK_O, 1
SPI_SDO_PIN = bit1
pulsout SPI_SCLK_O, 1
SPI_SDO_PIN = bit0
pulsout SPI_SCLK_O, 1
return[/FONT]
Definitions look like this:
[FONT=Courier New]symbol SPI_SCLK_O = B.2 ; SPI clock (output) 18M2 p8
symbol SPI_SDI = input6 ; SPI data (input) C.6 18M2 p15
symbol SPI_SDO = B.3 ; SPI data (output) 18M2 p9
symbol SPI_SDO_PIN = pinB.3 ; SPI data (output) in pinX.Y format.
symbol SPI_DATAB = b8 ; SPI write byte from here and read byte to here
symbol tempB0 = b14 ; temp working variable
symbol tempB1 = b15 ; temp working variable
Note the swerve already for SPI_SDO and SPI_SDO_PIN.
Any ideas?
Rgds
Damon
Last edited by a moderator: