I'm currently trying to communicatie Raspberry Pi 2 B+ with ADS7851, an adc chip made from TI. ADS7851_DATASHEET
I've done pretty much of research, but I'm still stuck on how to communicate in SPI with the device. Since most of the devices have 'Data In' port, which is connected to MOSI port in GPIO of RasPi. However, this one doesn't have such port. The only digital input port it has is CS(Chip Selecet) port, which I believe needs to be connected to CE0 port of RasPi. Therefore I think it is impossible to use xfer2 or xfer commands, which sends bytes from Master to Slave. So under this condition, I think I need to use spi.readbytes function right after I set CS active(LOW for this device), and the code I've so far written is below.
###########CODES##############
#!/usr/bin/python
import time
import sys
import spidev
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
spi=spidev.SpiDev()
spi.open(0,0)
spi.max_speed_hz=24000000 #16bits=1data, 1.5MSPS needed
SCLK=23
CS=24
MISO=21
GPIO.setup(SCLK,GPIO.OUT)
GPIO.setup(CS,GPIO.OUT)
GPIO.setup(MISO,GPIO.IN)
GPIO.output(CS,GPIO.HIGH) #initialize CS
def readADC(clkPin,csPin,misoPin):
buff=spi.readbytes(2)
bData=bin(buff[0])[2:].zfill(8)[2:]+bin(buff[1])[2:].zfill(8)
bData_rev=bData[::-1]
data=0
for bit in bData_rev:
data=(data<<1)|int(bit)
return data
if __name__=='__main__':
try:
while True:
GPIO.output(CS,GPIO.HIGH) #CS active
val=readADC(SCLK,CS,MISO)
volt=val*3.3/(2**14)
print 'ADC value', str(volt)
GPIO.output(CS,GPIO.LOW) #CS inactive
except KeyboardInterrupt:
GPIO.cleanup()
spi.close()
sys.exit(0)
#########################
However, this code doesn't work. More seriously, MISO only reads 0.
I'll be glad to hear any helpful advice. Thank you.
*Update
It's obvious that the picture itself is hard to understand. To explain it in detail with written words..
In ADS7851, 1. port 1 is connected to port 15, which is connected to mid-point of the variable resistor. 2. port2, port3, port8, port13, port16 is connected to ground 3. port4, port5, port6, port12 are left unconnected.(channel 2 not used) 4. port7(DVDD) is connected to 3.3V of raspi(GPIO pin 1) 5. port9(CS) is connected to raspi CE0 (GPIO pin 24) 6. port10(SCLK) is connected to raspi SCLK (GPIO pin 23) 7. port11(SDO A) is connected to raspi MISO (GPIO pin 21) 8. port14(AVDD) is connected to 5.0V of raspi(GPIO pin 2) 9. raspi GND(GPIO pin 6) is connected to ground 10. input signal comes from oscilloscope probe comp(5V, 1kHz square wave pulse), connected to one end of the variable resistor. The other end of the resistor is grounded.
Probing the ADC port 11, I could detect bundles of 16 pulses, which refers to the 16bits needed to send one data. So, ADC chip I believe works well. However, MISO still reads zeros only, and none of the commands xfer/xfer2/readbytes/pigpio works.