Skip to content

Instantly share code, notes, and snippets.

@jellea
Created June 6, 2016 07:58
Show Gist options
  • Save jellea/896e78c2b6ef802976cc09aa3907a412 to your computer and use it in GitHub Desktop.
Save jellea/896e78c2b6ef802976cc09aa3907a412 to your computer and use it in GitHub Desktop.
Nodemcu connecting with max113300
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