def run(self): #Only need to execute one of the following lines: #spi = SPI(bus, device) #/dev/spidev<bus>.<device> spi = SPI(0, 0) #/dev/spidev1.0 spi.msh = 2000000 # SPI clock set to 2000 kHz spi.bpw = 8 # bits/word spi.threewire = False spi.lsbfirst = False spi.mode = 1 spi.cshigh = False # chip select (active low) spi.open(0, 0) print("spi... msh=" + str(spi.msh)) gchannel = 0 buf0 = (7 << 3) | ((gchannel & 0x0f) >> 1) #(7<<3) for auto-2 mode buf1 = (gchannel & 0x01) << 7 buf1 = buf1 | 0x40 #select 5v i/p range while (self.running): ret = spi.xfer2([buf0, buf1]) print("0x%x 0x%x" % (ret[0], ret[1])) chanl = (ret[0] & 0xf0) >> 4 adcval = ((ret[0] & 0x0f) << 4) + ((ret[1] & 0xf0) >> 4) print(" -> chanl=%d adcval=0x%x" % (chanl, adcval)) time.sleep(1)
def ini_levels(): check_ok = 0 update_data = 0x39 # spi.set_clock_hz(1000000) # spi.set_mode(0) # spi.set_bit_order(SPI.MSBFIRST) SPI_PORT = 0 SPI_DEVICE = 0 # SPI setup spi = SPI(0, 0) #/dev/spidev1.0 spi.msh = 100000 # SPI clock set to 100 kHz spi.bpw = 8 # bits/word spi.threewire = False spi.lsbfirst = False spi.mode = 0 spi.cshigh = False # ADS1248 chip select (active low) # spi.open(0,0) spi.open(SPI_PORT, SPI_DEVICE) print "SPI port ", SPI_PORT, " ", SPI_DEVICE, " open"
#3V3 orange #OM SPI TE ENABLEN #config-pin P9.20 spi #en da me alle pins from Adafruit_BBIO.SPI import SPI import Adafruit_BBIO.GPIO as GPIO import time spi = SPI(0, 0) #4 busses, this is bus 0 spi.msh = 10000 #Frequency spi.bpw = 8 #bits per word spi.cshigh = False #true means you select the chip, depends on the chip, here low means active, normally Low for IMU spi.threewire = False #if it is true, you just read, otherwise you also send commands spi.lsbfirst = False #Least significant bit first (left) spi.open(0, 0) #open #GPIO.setup("P8_11",GPIO.OUT) #GPIO.output("P8_11",GPIO.HIGH) try: while True: res = spi.xfer2([0xFFFF, 0xFFFF]) #deliver two bytes res1 = spi.readbytes(2) #Read 2 bytes angle = (res1[0] << 8) | res1[1] #merge leftbyte and rightbyte angle1 = angle & 0x3FFF #move the first two bits angle2 = float(angle1) / 16363 * 360 print("data is")
RegWrite(ADS1248.MUX1, 0b00100000); # MUX1: REF0, normal operation RegWrite(ADS1248.SYS0, 0b00000000); # SYS0: PGA Gain = 1, 5 SPS RegWrite(ADS1248.IDAC0,0b00000000); # IDAC0: off RegWrite(ADS1248.IDAC1,0b11001100); # IDAC1: n.c. RegWrite(ADS1248.VBIAS,0b00000000); # VBIAS: BIAS voltage disabled RegWrite(ADS1248.OFC0, 0b00000000); # OFC0: 0 => reset offset calibration RegWrite(ADS1248.OFC1, 0b00000000); # OFC1: 0 => reset offset calibration RegWrite(ADS1248.OFC2, 0b00000000); # OFC2: 0 => reset offset calibration RegWrite(ADS1248.GPIOCFG, 0b00000000); # GPIOCFG: all used as analog inputs RegWrite(ADS1248.GPIODIR, 0b00000000); # GPIODIR: - RegWrite(ADS1248.GPIODAT, 0b00000000); # GPIODAT: - spi = SPI(0,0) #/dev/spidev1.0 spi.msh=10000 # SPI clock set to 100 kHz spi.bpw = 8 # bits/word spi.threewire = False spi.lsbfirst = False spi.mode = 1 spi.cshigh = False # ADS1248 chip select (active low) spi.open(0,0) GPIO.setup("P9_14", GPIO.OUT) # drive START high to start conversion GPIO.setup(ADS1248.STARTPIN, GPIO.OUT) GPIO.output(ADS1248.STARTPIN,GPIO.HIGH) time.sleep(0.02)