Skip to content

Commit 9e3b327

Browse files
committed
Add Eric's bit-banged SPI methods.
1 parent 574cc2f commit 9e3b327

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

PyduinoIncludes/SPI.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from IO import *
2+
3+
CS = D10
4+
MOSI = D11
5+
MISO = D12
6+
SCK = D13
7+
8+
c_spi_write = '\xf9\x01\x32\x97\x11\x81\x00\x81\xf8\x01\x51\x91\x8f\x01\x55\x23\xb1\xf0\x45\x2f\xf8\x01\x35\x2f\x61\x91\x28\xe0\x76\x98\x00\xc0\x67\xfb\x16\xf4\xa5\x9a\x01\xc0\xa5\x98\x00\xc0\x76\x9a\x00\xc0\x66\x0f\x2a\x95\x99\xf7\x3a\x95\x79\xf7\x4a\x95\x59\xf7\x08\x95'
9+
c_spi_read = '\xf9\x01\x40\xe0\x35\x97\x11\x80\x00\x24\x00\x81\x00\x0e\x14\x81\x00\xe0\x23\x81\x02\x2b\x0e\xc0\x76\x98\x00\xc0\x66\x0f\x1c\x99\x61\x60\x76\x9a\x3a\x95\x33\x23\xb9\xf7\xf8\x01\xe4\x0f\xf5\x1f\x61\x83\x43\x95\x50\xe0\x40\x15\x51\x05\x18\xf4\x60\xe0\x38\xe0\xf2\xcf\xf8\x01\x00\x82\x08\x95'
10+
11+
12+
def spi_init():
13+
# Initialize IO
14+
setPinDir(CS, True)
15+
writePin(CS, True)
16+
setPinDir(MOSI, True)
17+
writePin(MOSI, True)
18+
setPinDir(MISO, False)
19+
setPinDir(SCK, True)
20+
writePin(SCK, False)
21+
22+
def spi_write(data):
23+
call(c_spi_write, data)
24+
25+
def spi_read(num_bytes):
26+
myStr = '0'*20[:] # Allocate SPI buffer
27+
call(c_spi_read, num_bytes, myStr)
28+
return myStr

0 commit comments

Comments
 (0)