Page 1 of 1

GPIO - Trying to simultaneously use ADS1256 and DAC8532 via GPIO

Posted: Sun Mar 01, 2020 5:11 am
by mtapsak
Hi all, I am new to dealing with SPI and GPIO, and ran into an issue with the config files of the ADS1256 and DAC8532 on the Waveshare High-Precision AD/DA Board. https://www.waveshare.com/wiki/High-Pre ... /DA_Board

I would like to use both the AD and DA within the same python program, but I notice that the config files are slightly different. The config file for the ADS1256 defines its CS_PIN = 22, whereas the DAC8532 config uses CS_PIN = 23. Config for ADS:

Code: Select all

import spidev
import RPi.GPIO as GPIO
import time

# Pin definition
RST_PIN         = 18
CS_PIN       = 22
DRDY_PIN        = 17

# SPI device, bus = 0, device = 0
SPI = spidev.SpiDev(0, 0)

def digital_write(pin, value):
    GPIO.output(pin, value)

def digital_read(pin):
    return GPIO.input(DRDY_PIN)

def delay_ms(delaytime):
    time.sleep(delaytime // 1000.0)

def spi_writebyte(data):
    SPI.writebytes(data)
    
def spi_readbytes(reg):
    return SPI.readbytes(reg)
    

def module_init():
    GPIO.setmode(GPIO.BCM)
    GPIO.setwarnings(False)
    GPIO.setup(RST_PIN, GPIO.OUT)
    GPIO.setup(CS_PIN, GPIO.OUT)
    #GPIO.setup(DRDY_PIN, GPIO.IN)
    GPIO.setup(DRDY_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    SPI.max_speed_hz = 20000
    SPI.mode = 0b01
    return 0;
and the code for DAC is:

Code: Select all

import spidev
import RPi.GPIO as GPIO
import time

# Pin definition
CS_PIN = 23


# SPI device, bus = 0, device = 0
SPI = spidev.SpiDev(0, 0)

def digital_write(pin, value):
    GPIO.output(pin, value)

def digital_read(pin):
    return GPIO.input(pin)

def delay_ms(delaytime):
    time.sleep(delaytime // 1000.0)

def spi_writebyte(data):
    SPI.writebytes(data)
    
def spi_readbytes(reg):
    return SPI.readbytes(reg)
    

def module_init():
    GPIO.setmode(GPIO.BCM)
    GPIO.setwarnings(False)
    #GPIO.setup(RST_PIN, GPIO.OUT)
    GPIO.setup(CS_PIN, GPIO.OUT)
    #GPIO.setup(DRDY_PIN, GPIO.IN)
    #GPIO.setup(DRDY_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    SPI.max_speed_hz = 20000
    SPI.mode = 0b01
    return 0;
I'm hoping that there is an easy solution to make one config file so I can write python programs to access both chips. Thanks for any help.

Re: GPIO - Trying to simultaneously use ADS1256 and DAC8532 via GPIO

Posted: Sun Mar 01, 2020 6:32 pm
by DougieLawson
They can't both be device=0. That's what picks which chip select pin you're using.

Re: GPIO - Trying to simultaneously use ADS1256 and DAC8532 via GPIO

Posted: Sun Mar 01, 2020 9:26 pm
by mtapsak
Thank you for the reply, so can I have two devices on one SPI pin? Obviously one (say the ADS1256), is assigned to 0, so the other (DAC8532) is 1? I'm not sure how to implement.

Re: GPIO - Trying to simultaneously use ADS1256 and DAC8532 via GPIO

Posted: Sun Mar 01, 2020 10:47 pm
by DougieLawson