0

Background: I am trying to make transfer measurements from an ADC LTC1867 to my raspberry pi using SPI. I get it to work with one channel. The ADC has 8 channels, I have one channel connected to a 2.5V reference and one connected to ground. The ADC reads them when I only call spi.xfer2 once in my code.

I want to use the 2.5V reference channel to determine any offset or gain errors to correct my actual reading. However, in my code

def ReadChannel(channel):
  #Performs an SPI transaction.
  #Chip-select should be held active between blocks.
  #pi.spi_xfer([XXXXXXX,0])#sends 2 bytes 1st contains DIN, second is irrelevant
  #pin 7-GND=[244,0] connected to ground
  #pin 6-GND=[180,0] connected to 2.5V

  spi.close()
  spi.open(0,0)
  spi.max_speed_hz = 10000 
  channel_six = spi.xfer2([244,0])
  print channel_six
  spi.close()

  sleep(0.005)
  spi.open(0,0)
  spi.max_speed_hz = 10000 
  channel_seven = spi.xfer2([180,0])
  spi.close()

  print "ch6 array:{}".format(channel_six)
  print "ch7 array:{}".format(channel_seven)

  six_data = (channel_six[0]<<8) + channel_six[1]
  print "ch6:{}".format(six_data)
  sev_data = (channel_seven[0]<<8) + channel_seven[1]
  print "ch6:{}".format(sev_data)

  print "ch6 in Volts:{}".format(ConvertVolts(six_data,4))
  print "ch7 in Volts: {}".format(ConvertVolts(sev_data,4))
  return_six data

Below is a piscope graph of SCK, MISO, MOSI and CE0. enter image description here

The Data out is correct but the order is wrong. Channel 6 should be 2.5V and Channel 7 should be 0V. I guess I could swap them around but I wanted to know what exactly is going on.

Why do the values get swapped? How do I edit my code so the values come out the way I want (swapped)? Is there a way to add a small delay so they don't affect each other?

I tried a similar thing with pigpio and the results were similar.

  • As a matter of interest why do you keep opening and closing SPI? It would be normal to open once at the start of the program and close once at the end. – joan Feb 17 '17 at 11:59
  • @joan I thought it would help solve the problem. I thought that the two SPI transfers were interfering so I though closing and opening it would solve it – Baba Feb 17 '17 at 12:23
  • I'm going to guess you are misinterpreting the results. I haven't looked carefully at the datasheet but a cursory read leaves me confused. If the chip returns repeatable results I'd spend more time looking at the datasheet. – joan Feb 17 '17 at 12:36
  • @joan thanks! COuld you explain what you mean by repeatable results? – Baba Feb 17 '17 at 12:57
  • Try inputting three different voltages on a channel (say 0, middle, max). Do you get consistent but different readings for each voltage. That implies the processing chain of ADC->Pi is working, and sort of implies your interpretation of the readings is wrong. – joan Feb 17 '17 at 13:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.