Hello
I am trying to control an AD7490 16 channel ADC using spi0 on the beaglebone black, currently I am using a very simple code where all I want to do is get the ADC to read first channel i.e (channel 0) and return the value it gets, however it seems that the only two values that AD7490 returns are 255 and 16. Below is the code I am using
`
#!/usr/bin/python
from Adafruit_BBIO.SPI import SPI
import time
spi = SPI(0,0)
spi.msh=1000
spi.open(0,0)
spi.bpw=16
keepRunning=True
n=0
def readVoltages(n):
print("\n"+“talking to the ADC”)
readings=spi.xfer([65535,65535,(2097<<4)])
print(“output from first one”+"\n")
print(readings)
print("\n")
print(“I am awake now”)
print("\n")
readings=spi.xfer([(2097<<4)])
print(“This is what processor gave back “+”\n”)
print(readings)
print(“This is what the reading is “+”\n”)
print(readings[0]&4095)
print("\n")
adcOutput=readings[0]&4095
n+=1
return adcOutput,readings,n
while(keepRunning):
adcOutput, readings,n=readVoltages(n)
y_or_n=raw_input(“Should I run again??”)
print("\n"+y_or_n)
if(y_or_n is “n”):
keepRunning=False
n+=1;
print “I finished **********************”
spi.close()
Below is my output
talking to the ADC
output from first one
[255, 255, 16]
I am awake now
This is what processor gave back
[16]
This is what the reading is
16
Should I run again??n
n
I finished **********************
`
The structure of the control register of AD7490 is below
11 10 9 8 7 6 5 4 3 2 1 0
WRITE SEQ ADD3 ADD2 ADD1 ADD0 PM1 PM0 SHADOW WEAK/TRI RANGE CODING
The word size is 16 bits so when I want to program this ADC to read only first channel I send
2097<<4. But I always get 16, it does not matter whether I am applying any voltage to the ADC or not.
Please help me, its a very simple code and I cant think of a reason that it is not working.