-
Notifications
You must be signed in to change notification settings - Fork 1
/
spi.asm
69 lines (44 loc) · 961 Bytes
/
spi.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
;;; SPI
spiinit: lda #0x01 ; CPOL=0 and CPHA=1, which is
sta SPICONTROL ; needed by the DS1305
lda #0x02 ; div=2, which is E by 4
sta SPIDIV
lda #0xff ; "disable" the SS outputs
sta SPISS
rts
;;; SPI low level routines
spistart: sta SPISS
nop
rts
spistop: lda #0xff ; deassert chip select
sta SPISS
nop
rts
; spiwrite - send the byte in b
spiwrite: stb SPIDATAOUT
writeloop: tst SPISTATUS
bpl writeloop
rts
; spiwriteblock - sends y bytes from x
spiwriteblock: ldb ,x+
stb SPIDATAOUT
writeblockloop: tst SPISTATUS
bpl writeblockloop
leay -1,y
bne spiwriteblock
rts
; spiread - read the next spi byte into b
spiread: clr SPIDATAOUT
readloop: tst SPISTATUS
bpl readloop
ldb SPIDATAIN
rts
; spireadblock - read y bytes into the buffer starting at x
spireadblock: clr SPIDATAOUT
readblockloop: tst SPISTATUS
bpl readblockloop
ldb SPIDATAIN
stb ,x+
leay -1,y
bne spireadblock
rts