mtapsak
Posts: 2
Joined: Sun Mar 01, 2020 4:41 am

GPIO - Trying to simultaneously use ADS1256 and DAC8532 via GPIO

Sun Mar 01, 2020 5:11 am

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.

User avatar
DougieLawson
Posts: 39296
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

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

Sun Mar 01, 2020 6:32 pm

They can't both be device=0. That's what picks which chip select pin you're using.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

mtapsak
Posts: 2
Joined: Sun Mar 01, 2020 4:41 am

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

Sun Mar 01, 2020 9:26 pm

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.

User avatar
DougieLawson
Posts: 39296
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

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

Sun Mar 01, 2020 10:47 pm

Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Return to “Automation, sensing and robotics”