Shop OBEX P1 Docs P2 Docs Learn Events
ADS7828 i2c ADC — Parallax Forums

ADS7828 i2c ADC

JonathanJonathan Posts: 1,023
edited 2008-04-06 20:10 in Propeller 1
Hi All,

I'm trying to use a ADS7828 with the prop. Trouble is that I am using a breakout board for it (it's a TSSOP package) and so I can't be %100 sure that I have it mounted OK. So, I'm hoping someone can look at this code and tell me if it ought to be working or not. The ADC is set to address $A0, meaning both address pins are tied to ground. I have a 4.7k pullup on both SDA and CLK. I am using the basic i2c object, clk is set to pin 6 and sda to one higher, 7.
CON
    _clkmode = xtal1 + pll16x
    _xinfreq = 5_000_000
    ' PropTerm
    #0, WHITE,CYAN,RED,PINK,BLUE,GREEN,YELLOW,GRAY 
   ' ADC
   adcClock     = 6  ' adcData = 7
   adcAddr      = $A0

VAR
word adcResult
 
OBJ
term            : "PC_Interface" 
adc             : "Basic_I2C_Driver"  
   
PUB init
  term.start(31,30) 
  term.str(string("House Controller 0.0.1")) 
  wait_ms(1000)
  
repeat
  term.out(0)
  adc.initialize(adcClock)
  adc.start(adcClock)
  'adc.write(adcClock,adcAddr)
  adc.write(adcClock,%1001_0001)
  adc.write(adcClock,%1111_1111)
  adcResult.byte[noparse][[/noparse]0] := adc.read(adcClock,adcAddr)
  adcResult.byte[noparse][[/noparse]1] := adc.read(adcClock,adcAddr)
  term.str(string("ADC result: "))
  term.dec(adcresult)
  wait_ms(500)

Any help would be much appreciated. I want to use this part so that I can use the eeprom i2c lines to save pins. All I get now for the adcResult is 65535.

Thanks!

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.madlabs.info - Home of the Hydrogen Fuel Cell Robot

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-04-05 16:55
    You're using very low level I2C routines (start / read / write / stop) that don't do what you expect them to do. You might be better off looking at James Burrows' i2cObjectv2 from the Object Exchange which is based on the same low level routines, but includes higher level routines for a variety of I2C devices that you might be able to use as your model.

    Look at the datasheets for the ADC. You'll find that all write transfers begin with a start transition (using adc.start) followed by a device select code (adc.write) followed by a command byte (adc.write) followed by a stop transition (adc.stop). All read transfers begin with a start transition, a device select code (adc.write) that indicates this is a read operation, followed by reads (adc.read) and a final stop transition. The reads have to have an acknowledge bit set true except for the last byte where it is false. Look at the examples in James' device objects.
  • JonathanJonathan Posts: 1,023
    edited 2008-04-05 17:02
    Mike,

    Thanks for the help. I'll go get the object you reccomend. I'll also go get the datasheets for the devices James uses in the object. Hopefully I'm on the road to success!

    Thanks again, I really appreciate the help!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • JonathanJonathan Posts: 1,023
    edited 2008-04-06 20:10
    Mike,

    Thanks for the help. I finally got it to work. I had a variety of both harware and software issued. James's devicepresent routine got me on the right path. I'll be making a little object for this device for the OBEX.

    Thanks again!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
Sign In or Register to comment.