This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

ADS131M03: SPI issue

Part Number: ADS131M03

Hi,

I am using the ADS131M03 with the raspberry pi 3B and program through python. The ADC is clocked by an 8.192 MHz external MEMS oscillator. The SPI rate is set at 32 kSPS (I also tried 3.2 k and 320 Hz). The system previously worked in the protoboard but not working in the PCB. The captured waveform is shown as attached (First: DRDY, Second: Datain, Third: SCLK, 4th: Data out). I was trying to read the Gain register, but it returns 255 response and none of the channel data (same results while trying to read 0x00 register), which is clearly not correct.

One interesting thing is that when I was trying to probe to CLKIN pin (which is connected to the external clock), the chip is able to output readout results but different each time, the captured waveform is attached: (1st: DRDY, 2nd: CLKIN, 3rd: SCLK 4th:Dataout)

The codes I am using is attached, I used the 0.0000125 delay in reset pin to sync but seems not working.

 

import time
import spidev
import RPi.GPIO as GPIO
import sys
# clk is a mini class to generate a Master-Clock signal over a PWM Pin


#and also a function which gets two hex numbers and gives back the "Message" for send
#settings
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_UP)   #Pin 17 --> DRDY Pin
GPIO.add_event_detect(17,GPIO.FALLING)

GPIO.setup(8, GPIO.OUT)                             #Pin 8 --> CS'
GPIO.output(8,1)
GPIO.setup(2, GPIO.OUT)                             #Pin 2 --> RESET/SYNC
GPIO.output(2,1)
spi = spidev.SpiDev()

spi.open(0,0) 
spi.mode=0b01                                       #CPOL=0, CPHA=1; resting state = 0, data read at falling edge

spi.max_speed_hz =32000
spi.bits_per_word = 8
spi.lsbfirst = False



def read():
    GPIO.output(8,0)
##    time.sleep(0.000125)
##    GPIO.output(2,0)
##    time.sleep(0.000125)
##    GPIO.output(2,1)
##    time.sleep(0.000125)
    send_data = [0b10100000,0b10000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000]
    com_reg=spi.xfer2(send_data)
    
  
    if GPIO.event_detected(17):
        send_data = [0b10100000,0b10000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000]
        
    # read null response
        com_reg=spi.xfer2(send_data)
##        com_reg=spi.readbytes(15)
        result1 = (8388608-abs(com_reg[3]*256*256+com_reg[4]*256+com_reg[5]-8388608))*0.00000014
        result2 = (8388608-abs(com_reg[6]*256*256+com_reg[7]*256+com_reg[8]-8388608))*0.00000014
        result3 = (8388608-abs(com_reg[9]*256*256+com_reg[10]*256+com_reg[11]-8388608))*0.00000014
        result1 = str(result1)
        result2 = str(result2)
        result3 = str(result3)
        time1 = time.strftime("%H:%M:%S ")
        print("channel1: "+result1+" V")
        print("channel2: "+result2+" V")
        print("channel3: "+result3+" V")
        print("read2")
        print (com_reg)
        file.write("prototest  ")
     
        file.write(time1)
        file.write("channel1: "+result1+" V  ")
     
        file.write("channel2: "+result2+" V  ")
       
        file.write("channel3: "+result3+" V")
        file.write("\n")
        
        
    GPIO.output(8, 1)
    time.sleep(1)

def Gain_config():
    GPIO.output(8,0)
    if GPIO.event_detected(17):
        datawreg = [0b01100010, 0b00000000,0b00000000,0b00000000, 0b00000000,0b00000000,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]
        com_reg=spi.xfer2(datawreg)
        result1 = (8388608-abs(com_reg[3]*256*256+com_reg[4]*256+com_reg[5]-8388608))*0.00000014
        result2 = (8388608-abs(com_reg[6]*256*256+com_reg[7]*256+com_reg[8]-8388608))*0.00000014
        result3 = (8388608-abs(com_reg[9]*256*256+com_reg[10]*256+com_reg[11]-8388608))*0.00000014
        result1 = str(result1)
        result2 = str(result2)
        result3 = str(result3)
        print("channel1: "+result1+" V")
        print("channel2: "+result2+" V")
        print("channel3: "+result3+" V")
        print("gain")
        print (com_reg)
        
    GPIO.output(8, 1)
    time.sleep(1)   
def send_unlock():
# GPIO.output(18, False)
    GPIO.output(8,0)
    if GPIO.event_detected(17):
        send_data = [0b00000110, 0b01010101,0b00000000,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]       
        com_reg=spi.xfer2(send_data)
        print("unlock")
        print (com_reg)        
    GPIO.output(8, 1)
    time.sleep(1)
def send_null():
    GPIO.output(8,0)
##    time.sleep(0.000125)
##    GPIO.output(2,0)
##    time.sleep(0.000125)
##    GPIO.output(2,1)
##    time.sleep(0.000125)    
    # read null response
##    print("null1")
##    print (com_reg)
    if GPIO.event_detected(17):
        send_data = [0b00000000,0b00000000, 0b00000000,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]
    # read null response
        com_reg=spi.xfer2(send_data)
        
##    com_reg=spi.readb
        print("null")
        print (com_reg)
        print (com_reg[12])
        result1 = (8388608-abs(com_reg[3]*256*256+com_reg[4]*256+com_reg[5]-8388608))*0.00000014
        result2 = (8388608-abs(com_reg[6]*256*256+com_reg[7]*256+com_reg[8]-8388608))*0.00000014
        result3 = (8388608-abs(com_reg[9]*256*256+com_reg[10]*256+com_reg[11]-8388608))*0.00000014
        result1 = str(result1)
        result2 = str(result2)
        result3 = str(result3)
        print("channel1: "+result1+" V")
        print("channel2: "+result2+" V")
        print("channel3: "+result3+" V")
    GPIO.output(8, 1)
    time.sleep(1)
def send_reset():
# GPIO.output(18, False)
    GPIO.output(8,0)
##    time.sleep(0.000125)
##    GPIO.output(2,0)
##    time.sleep(0.000125)
##    GPIO.output(2,1)
##    time.sleep(0.000125)
    if GPIO.event_detected(17):
        send_data = [0b00000000, 0b00010001,0b00000000,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]       
        com_reg=spi.xfer2(send_data)
        print("reset2")
        print (com_reg)        
    GPIO.output(8, 1)
    time.sleep(1)
def send_wakeup():
# GPIO.output(18, False)
    GPIO.output(8,0)
    if GPIO.event_detected(17):
        send_data = [0b00000000, 0b00110011,0b00000000]
        com_reg=spi.xfer2(send_data)
        print (com_reg)
    
    GPIO.output(8, 1)
    time.sleep(1)
def Clock_config():
    GPIO.output(8,0)
    if GPIO.event_detected(17):
        datawreg = [0x61,0x80,0x00,0x07,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]
        dataw=spi.xfer2(datawreg)
        
        print("clock")
        print (dataw)
      
    GPIO.output(8, 1)
    time.sleep(1)

def CFG_config():
    GPIO.output(8,0)
    if GPIO.event_detected(17):

    #data write into the CFG Register (Address: 06h)
    #Value written: 0700h, enables Global Chop and sets Global Chop Delay
    #CRC word added, Value = 1021h
    #datawreg = [0x66,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]
        datawreg = [0b01100011, 0b00000000, 0b00000000, 0x07,0x00,0x00,0x10,0x21,0x00,0x00,0x00,0x00,0x00,0x00,0x00]
        dataw=spi.xfer2(datawreg)
        print("cfg")
        print (dataw)
   
    GPIO.output(8, 1)
    time.sleep(1)

def MODE_config():
    GPIO.output(8,0)
    if GPIO.event_detected(17):
    #data write into the MODE Register (Address: 03h)
    #Value written: 3510h, enables CRC and sets CRC type
    #CRC word added, Value = 1021h
        datawreg = [0b01100001, 0b0000000,0b00000000,0x35,0x10,0x00,0x10,0x21,0x00,0x00,0x00,0x00,0x00,0x00,0x00]
        dataw=spi.xfer2(datawreg)
        print("mode")
        print (dataw)    

    GPIO.output(8, 1)
    time.sleep(1)

##
##GPIO.output(8,0)
if GPIO.event_detected(17):
    GPIO.output(2,0)
    time.sleep(0.0000125)
    GPIO.output(2,1)
##read2()
##time.sleep(0.0125)
##GPIO.output(2,0)
##time.sleep(0.000125)
##GPIO.output(2,1)
##########
file = open('/home/pi/Documents/EMILIE/proto517.txt', 'a+')
##send_unlock()
##send_reset()
####
##send_reset()
##Clock_config()
##Gain_config()
########
####send_wakeup()
send_null()
##MODE_config()
##CFG_config()
##
####send_null()
##Gain_config()
while True:
##    GPIO.output(8,0)
    if GPIO.event_detected(17):
        read()
##        send_reset()
##        send_null()
##        send_wakeup()
##
##send_reset()
##Clock_config()
##Gain_config()
##CFG_config()
##send_wakeup()
##send_null()
##MODE_config()
##GPIO.output(8,0)
##while True:
##    if GPIO.event_detected(17):         # Read conversion data
##        
##       
##
##        data=spi.xfer2([0x00, 0x00, 0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00])
##        print("receive some Data")
##            
##        print(data)
        
            

spi.close()    

The Schematic is attached: 

Looking forward to have your suggestion!

Best regards,

Zeyu

  • Hi Zeyu,

    Welcome to the E2E forum.  When your send a RREG command to M03 ADC for reading an internal register data, the register data will be shifted out in the next frame. In your 1st timing, you continued sending RREG command in each frame, this is the reason you could not see the register data back from the M03 ADC. Below is a timing I captured on the EVM for your reference, A200h command was sent to the M0x ADC in the 1st frame to read GAIN register (04h address), the GAIN register data (1000h) was shown in the 2nd frame. Note that the default value for GAIN register on M03 ADC is 0000h after the ADC is powered up, I actually had written 1000h to the GAIN register to set the gain of CH2 to 2 in advance so that a clear register data can be seen and checked on DOUT.

    For your 2nd timing, I did not know whether you were trying to read registers or not, I saw some signals on your Datain, but notice that the clock is sensitive to the capacitance which can be impacted by your probe.

    Regards,

    Dale

  • Hi Dale,

    Thanks for your help. I tried to send two 24 bits words and expecting the see the right response in the second word but the response is not right. The captured waveform is shown below (1st SCLK 2nd Dataout 3rd Datain 4th CS). I am attempting to read the mode register (02) this time but the response is not what I expected (0510).

    I also monitored the DRDY pin behavior (second figure channel 4) and it seems kept going up unexpectedly. Since the DRDY is only generated by the ADC, I am wondering may I know what could be the possible cause for that?

    Best regards,

    Zeyu

  • Hi Zeyu,

    What's your SCLK frequency? it's not easy to see. Also, I saw your /DRDY is always low with spikes in your last timing, it seems the /DRDY is affected by interference signals in your system.

    Is your DOUT directly connected to your controller or shared with other devices? Can you provide a clear schematic? What's the difference between your protoboard and this PCB? Have you tried another ADC device?

    Thanks&regards,

    Dale

  • Hi Dale,

    I set the spi speed at 32 kHz, I am wondering do you have any recommendation spi speed range for the ADC? I do see the DRDY has a spikes every 250 us once the device is powered up, is that normal? 

    The Dout is connected directly to the MCU but through long cables and connectors (about 50 cm long wire). I measured the cable resistance and it is 1 Ohm. I am wondering does any type of source termination method would be required in that case? The protoboard has the same schematic but shorter wires, I have not tried any other type of ADC yet.

    best regards,

    zeyu

  • Hi Zeyu,

    The maximal SCLK frequency is 25MHz at3.3DVDD power supply. the minimal frequency depends on your data rate, it will okay as long as you can read out the data of all channels.

    These /DRDY spikes are not generated by the ADC, they should be caused by your pcb or your system. 50cm wire are pretty long. Can you provide a photo for your setup?

    Did you monitor these signals in your timing close to the ADC? if not, I suggest you to monitor them with probes close the pins of the ADC as you can.

    Regards,

    Dale

  • Got it, so I think 100 kHz to 500 kHz would be a safe range for this application. The photo for the setup is attached, the PCB itself has a long copper trace for the SPI line and it went through a connector board with 8 position cable then go to a FPC to DIP board soldered with jump wire and finally go to the Raspberry Pi. I am wondering which part would you think may have most noise issue?

    Since the PCB is designed very compact, it is very hard to probe the DRDY pin for the PCB. I probed the ADC DRDY pin from the protoboard (The DRDY pin is in the first trace). Although the protoboard data out is correct, there are still two spikes during the transmission of the fifth word, I am wondering is that normal?

    Best regards,

    Zeyu

  • Hi Zeyu,

    You cables are too long for SPI signals. I would suggest you cut and make them as short as possible. 

    These spikes are not "normal", they were probably caused by your setup and long cables. I did not see them on our M04EVM board.

    Can you post a clear schematic so that I can check in case any potential issues?

    Regards,

    Dale

  • Got it, I could reduce the on board spi trace length from 12 cm to 10 cm and I could remove the use of the FFC cable and replace the on board connector type to pin head connector if you recommend it. The jump wire cable length can be reduced from 30 cm to 15 cm. Would you think a shielded cable or twisted cable could be better than the regular jumper wire?

    I used an external MEMS oscillator SIT8924B to provide 8.192 MHz clock to the ADC, which is placed very closed to the ADC shown as attached layout screenshots. I wondering could this oscillator cause any issue to the DRDY or the long SPI lines be more major issue? The schematic is also attached which includes the ADC the oscillator the EMI shield, please check.

    Best regards,

    Zeyu

  • Hi Zeyu,

    a shielded cable or twisted cable will be helpful, but I'm sure if it can solve the issue because your trace and cable are long. Try to make them as short as possible.

    Both the oscillator and the long SPI lines could cause the issue because you have very limited space on the pcb board and also the long cable could make it worse. 

    Regards,

    Dale