Created
June 6, 2016 07:58
-
-
Save jellea/896e78c2b6ef802976cc09aa3907a412 to your computer and use it in GitHub Desktop.
Nodemcu connecting with max113300
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
pin = 8; | |
gpio.mode(pin,gpio.OUTPUT); | |
gpio.write(pin,gpio.HIGH); | |
spi.setup(1, spi.MASTER, spi.CPOL_LOW, spi.CPHA_LOW, spi.DATABITS_8, 0,spi.FULLDUPLEX); | |
gpio.write(pin,gpio.LOW); | |
function readRegister(address) | |
gpio.write(pin,gpio.HIGH); | |
gpio.write(pin,gpio.LOW); | |
spi.send(1, bit.lshift(0x01, address)); | |
r1 = {spi.send(1, 0)}; | |
r2 = {spi.send(1, 0)}; | |
bb = bit.lshift(r1[2], 8); | |
print (bb); | |
print (r2[2]); | |
print("==" .. bb+r2[2]); | |
gpio.write(pin,gpio.HIGH); | |
end | |
function writeRegister(address, value) | |
gpio.write(pin,gpio.HIGH); | |
gpio.write(pin,gpio.LOW); | |
spi.send(1, bit.lshift(0x01, address)); | |
spi.send(1, bit.rshift(8, value)); | |
spi.send(1, bit.band(0xFF, value)); | |
gpio.write(pin,gpio.HIGH); | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment