A small, affordable computer with free resources to help people learn, make things, and have fun
https://forums.raspberrypi.com/
Code: Select all
import spidev as SPI
import RPi.GPIO as GPIO
CS = 24
def spi_write(register, data):
GPIO.output(CS, GPIO.LOW)
resp = spi.xfer2([register, data], 2000000)
GPIO.output(CS, GPIO.HIGH)
def spi_read(register):
GPIO.output(CS, GPIO.LOW)
resp = spi.xfer2([register | 0x80, 0], 2000000)
GPIO.output(CS, GPIO.HIGH)
return resp[1]
try:
spi = SPI.SpiDev()
spi.open(0, 0)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(CS, GPIO.OUT, GPIO.HIGH)
spi_write(0x0B, 0)
for d in [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25]:
resp = spi_read(d)
print (resp)
spi_write(0x0B, 1)
except Exception as x:
print (x)
#GPIO.cleanup()
spi.close()