I'm trying to use ads8688 with my BeagleBoard. The part responds to setting/reading registers, but starting conversions is a no go. AVDD is 5V, DVDD is 3.3V.
This is the python script I wrote:
#!/usr/bin/python from Adafruit_BBIO.SPI import SPI def ad_wreg(reg, d): r = spi.xfer2([reg*2+1, d, 0]) if r[2] != d: raise Exception('error writing reg') def ad_rreg(reg): r = spi.xfer2([reg*2, 0, 0]) return r[2] def ad_cmd(cmd): r = spi.xfer2([cmd,0,0,0]); return r[2:] # --- main --- spi = SPI(2,0) spi.msh=100000 spi.bpw=8 spi.mode=1 ad_cmd(0x85) # reset program registers ad_wreg(3, 3) # set features for i in range(1,0x0d): # dump registers if i == 4: continue # no register 4 print hex(i),hex(ad_rreg(i)) ad_cmd(0xa0) # auto_rst print 'starting auto' print 'cmd',hex(ad_rreg(0x3f)) # command read-back for i in range(8): print i,spi.xfer2([0,0,0,0,0,0]) # no_op = auto_scan spi.close()
The code produces the following output:
0x1 0xff
0x2 0x0
0x3 0x3
0x5 0x0
0x6 0x0
0x7 0x0
0x8 0x0
0x9 0x0
0xa 0x0
0xb 0x0
0xc 0x0
starting auto
cmd 0x0
0 [0, 0, 255, 255, 255, 128]
1 [0, 0, 255, 255, 255, 128]
2 [0, 0, 255, 255, 255, 128]
3 [0, 0, 255, 255, 255, 128]
4 [0, 0, 255, 255, 255, 128]
5 [0, 0, 255, 255, 255, 128]
6 [0, 0, 255, 255, 255, 128]
7 [0, 0, 255, 255, 255, 128]
I've verified the SPI signals with an oscilloscope. Everything looks fine. Furthermore, to rule out SPI glitches, I've set register 1 (AUTO_SEQ_EN) to every possible 8 bit value and read it back to verify. I.e. like this:
for i in range(0x100):
ad_wreg(1, i)
if i != ad_rreg(1):
raise Exception('err')
I've done this several thousand times, no errors.
So the register writing/reading is ok, however starting a conversion, either with 0xa0 or 0xcx (for example 0xcc) always produces the above output. The command read back always returns 0. So at first glance, the chip will not start converting. However, inspecting the extra feature data (after the 16 bit result) seems to suggest more things are wrong. The channel address should change in auto mode, it does not. But ok, that can be explained with the chip not entering auto mode. The device address bits should be b00, since the feature register is 0x03, they're b11. The LSB of input voltage range should be b000, since the ranges for all channels are b0000, they're b111.
If I set feature to 0 the device will output:
[0, 0, 255, 255, 0, 0]
for all channels.
If I set feature to 1 the device will output:
[0, 0, 255, 255, 240, 0]
for all channels.
SPI mode is correct and I've tried all other modes. Mode 0 and 3 immediately fail at the register write/verify function, mode 2 works the same as mode 1.
I've now spent 3 days trying to figure this out with no luck. I'm ready to conclude the chip is malfunctioning. Help would be appreciated.
Oh, and commands do work, i.e. if I set some registers and then issue 0x85 command, the registers are returned to default.
Thank you,
Stewie