Last active
December 11, 2016 02:47
-
-
Save yamori813/40efce7ddd4d0b0bb9da557a0367a8a1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://dlnware.com/theory/SPI-Transfer-Modes | |
$sck = 7 | |
$cs = 1 | |
$mosi = 3 | |
$miso = 4 | |
def txbyte(t, ch) | |
for num in 0..7 do | |
if (ch & (0x80 >> num)) == 0 then | |
t.set($mosi,0) | |
p 0 | |
else | |
t.set($mosi,1) | |
p 1 | |
end | |
t.set($sck,1) | |
usleep(10) | |
t.set($sck,0) | |
usleep(10) | |
end | |
end | |
def rxbyte(t) | |
for num in 0..7 do | |
t.set($sck,1) | |
p t.get($miso) | |
usleep(10) | |
t.set($sck,0) | |
usleep(10) | |
end | |
end | |
t = BsdGpio.new(0) | |
t.setflags($cs, BsdGpio::OUTPUT) | |
t.setflags($mosi, BsdGpio::OUTPUT) | |
t.setflags($miso, BsdGpio::INPUT) | |
t.setflags($sck, BsdGpio::OUTPUT) | |
t.set($sck,0) | |
usleep(10) | |
t.set($sck,1) | |
usleep(10) | |
t.set($cs,0) | |
usleep(10) | |
t.set($sck,0) | |
usleep(10) | |
txbyte(t, 3) | |
txbyte(t, 0) | |
rxbyte(t) | |
t.set($cs,1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment