Part Number: ADS8698 Tool/software: Hope you guys are doing well I would like to ask about some help, I needed to make data acquisition with ADS8698 and since I am very new to SPI I don't understand what exactly I am doing wrong please help with this. I have following board with ADS8698 https://www.aliexpress.com/item/1005006570383341.html ADS8698 datasheet https://www.ti.com/lit/ds/symlink/ads8698.pdf?ts=1730097926835&ref_url=https%253A%252F%252Fwww.ti.com%252Fproduct%252FADS8698 I am connected SPI pins and Potentiometer to V on Raspi 5V and GND on Raspi GND and Middle pint to AIN0 Board VIN => 5V raspi Board GND => GND raspi following is my code and thing is that I am getting same value from adc if I connect input to AIN0 or not and even if I just read response just after RST command I still get same value when I print adc_val = 255 Also is it correct that I need to convert adc value to voltage as following? adc_val * 10.24 / ( 2 ** 18) # config.py --------------------------------------------------------------- import time import RPi.GPIO as GPIO import spidev RST_PIN = 25 CS_PIN = 8 SPI = spidev.SpiDev() SPI.open(0, 0) def digital_write(pin, value): GPIO.output(pin, value) def delay_ns(ns): time.sleep(ns * 1e-9) def spi_writebyte(data): SPI.writebytes(data) def spi_readbytes(reg): return SPI.readbytes(reg) def module_init(): GPIO.setmode(GPIO.BCM) print(1) GPIO.setwarnings(False) print(2) GPIO.setup(RST_PIN, GPIO.OUT) print(3) GPIO.setup(CS_PIN, GPIO.OUT) SPI.max_speed_hz = 18_000_000 #18MHz SPI.mode = 1 return 0 # End Config # ads.py --------------------------------------------------------------- import config import RPi.GPIO as GPIO CMD_REG = { 'NO_OP' : 0x0000, # Continue operation in previous mode 'STDBY' : 0x8200, # Device is placed into standby mode 'PWR_DN' : 0x8300, # Device is powered down 'RST' : 0x8500, # Program register is reset to default 'AUTO_RST' : 0xA000, # Auto mode enabled following a reset 'MAN_Ch_0' : 0xC000, # Channel 0 input is selected 'MAN_Ch_1' : 0xC400, # Channel 1 input is selected 'MAN_Ch_2' : 0xC800, # Channel 2 input is selected 'MAN_Ch_3' : 0xCC00, # Channel 3 input is selected 'MAN_Ch_4' : 0xD000, # Channel 4 input is selected 'MAN_Ch_5' : 0xD400, # Channel 5 input is selected 'MAN_Ch_6' : 0xD800, # Channel 6 input is selected 'MAN_Ch_7' : 0xDC00, # Channel 7 input is selected 'MAN_AUX' : 0xE000 # AUX channel input is selected } rest = [ 0x85, 0x00] class ADS: def __init__(self): self.rst_pin = config.RST_PIN self.cs_pin = config.CS_PIN def ADS_reset(self): config.digital_write(self.rst_pin, GPIO.HIGH) config.delay_ns(100) config.digital_write(self.rst_pin, GPIO.LOW) config.delay_ns(100) # config.spi_writebyte(rest) config.spi_writebyte([CMD_REG['RST']] ) config.digital_write(self.rst_pin, GPIO.HIGH) # config.delay_ns(100) def ADS_Write_Cmd(self, cmd_reg): config.digital_write(self.cs_pin, GPIO.LOW) config.spi_writebyte([cmd_reg] ) config.digital_write(self.cs_pin, GPIO.HIGH) def ADS_Read_ADC_Data(self): config.digital_write(self.cs_pin, GPIO.LOW) config.spi_writebyte([CMD_REG['NO_OP']]) buf = config.spi_readbytes(3) config.digital_write(self.cs_pin, GPIO.HIGH) read = (buf[0]<<16) & 0xff0000 read |= (buf[1]<<8) & 0xff00 read |= (buf[2]) & 0xff return read def ADS_init(self): if (config.module_init() != 0): return -1 self.ADS_reset() return # End ADS # main.py --------------------------------------------------------------- import ADS import RPi.GPIO as GPIO try: ADC = ADS.ADS() ADC.ADS_init() # ADC.ADS_Write_Cmd(ADS.CMD_REG['MAN_Ch_0']) # result = [] while(1): adc_val = ADC.ADS_Read_ADC_Data() print("ADC = %lf "%(adc_val * 10.24 / (2 ** 18))) print(adc_val ) except : GPIO.cleanup() print ("\r\nProgram end ") exit() # End Main I would be grateful if you could explain how to do it correctly, I would like to get 150KSPS. I guess it is mostly about CLK timings?
↧