Shop OBEX P1 Docs P2 Docs Learn Events
i2c 3.3V to 5V — Parallax Forums

i2c 3.3V to 5V

JonathanJonathan Posts: 1,023
edited 2008-05-11 16:47 in Propeller 1
Hi All,

I am working with the ADS7828 i2c ADC. I have got it working nicely at 3.3V. However, I need to run it at 5V to sample some 5V sensors. My goal is to eventually use the props dedicated i2c pins. Right now I am using pins 6-7 on a demo board.

I have looked in the "Safely interfacing 5V" thread, and have tried both Tracey's two resistor setup and Beau's two transistor setup. With Tracey's setup, the ADC reads correctly once, on start up. With Beau's setup, I get nothing or 65535, depending on where I place the pullups.

Any ideas? Thanks!

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

Comments

  • GadgetmanGadgetman Posts: 2,436
    edited 2008-04-09 15:37
    Why not just use a voltage divider to reduce the voltage output from the sensors?
    It's just a couple of resistors, so...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don't visit my new website...
  • RaymanRayman Posts: 14,162
    edited 2008-04-09 15:55
    I used a level shifting IC.· But, it's only surface mount...

    I've got links to the two types I've used at the bottom on this page:

    http://www.rayslogic.com/propeller/Programming/i2c/i2c.htm
  • JonathanJonathan Posts: 1,023
    edited 2008-04-09 16:11
    Ray,

    Thanks for the link. I'll go that route if I have to, but seeing that I can get one good reading, there ought to be a way to make it work without. I hope. [noparse]:)[/noparse]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • JonathanJonathan Posts: 1,023
    edited 2008-04-09 16:12
    Odd, my post to gadget didn't show up. The divider wont work as it will drop the resolution of the sensor too much.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • Paul BakerPaul Baker Posts: 6,351
    edited 2008-04-09 16:32
    Jonathan, instead of reducing the signal strength, try the following circuit on the digital interface between your prop and your ADC running at 5V.
     
       5V
        ^
        |
        \
        /
        \ 3R
        /       R
    5V -+-----/\/\/----- 3.3V device device 
    
    

    I find this configuration works pretty well. I use this circuit to boost a 3.3V signal to trigger 5V Vih = 0.7 Vdd devices, it will still trigger the Vil = 0.3 Vdd low as well. The boost is sufficent to use 5% resistors and still trigger under worst case. I personally use 1k and 3k, but any 1:3 ratio will work and for I2C devices larger values should probably be used.

    The nice thing about this circuit is that it can be used bi-directionally, where the series resistor·acts as the current limiter for 5V·device·generated output.·

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.

    Post Edited (Paul Baker (Parallax)) : 4/9/2008 4:38:10 PM GMT
  • JonathanJonathan Posts: 1,023
    edited 2008-04-09 17:59
    Paul,

    I tried your setup using 3.2k and 10k. I'm guessing that is close enough to 3:1. No joy, and I don't even get the one reading. Looking at it on the scope, it seems that the signals are very similar, the clock idles high and it all looks pretty much the same. Of course, I don't really know what I would be lookig for. I don't get why it would work once unless it was something like the clock not being left in the correct state, or something like that.

    I'm wondering if it might be hardware. I used a breakout board to take the TSSOP package out to DIP. Maybe I have a dodgy connection. I have another, so I'll try that.

    Any other ideas? I really want it to work so I can move on. [noparse]:)[/noparse]

    Thanks for the help!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • JonathanJonathan Posts: 1,023
    edited 2008-04-09 18:55
    A little more data:

    Looking closer at the scope traces, the succssesful reading shows 4 clock cycles, then the ACK on the data line. On the failed attempt, it doesn't start that way. I'm going to try to attach a BMP from the 'scope to illustrate. The i2cOK shows the first read upon restarting the Prop. The i2cNO file shows what all the subsequent reads look like. I have tried a second ADC and it behaves the same. Blue is clock, red is data.

    Drat. I keep getting an error when I try to upload the BMP's.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • Paul BakerPaul Baker Posts: 6,351
    edited 2008-04-09 21:13
    BMPs aren't supported for uploading because of the waste of bandwidth (they don't do any compression). You can use paint or any other drawing program to save it as a gif or jpg.

    Alternatively you can zip the file and post it that way.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • JonathanJonathan Posts: 1,023
    edited 2008-04-09 21:30
    Thanks for the tip. Here are the scope shots in JPEG format, just in case it helps.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
    792 x 545 - 81K
    792 x 545 - 81K
  • JavalinJavalin Posts: 892
    edited 2008-04-10 10:31
    I've used Pauls circuit but with the a 4.7k pull up to 3.3v on the propeller side of the "R"

    A 1K Resistor to the 5v stuff works well.

    Have a look at the i2cObject version 2 in the Object exchange - the i2cDemo.spin has pictures.

    If that doesn't work - i'd check your setup. Start with a single device and keep adding gradually.

    J
  • JonathanJonathan Posts: 1,023
    edited 2008-04-10 14:40
    Javalin,

    I've tried all of that. I have got other i2c devices to work at 5V. For some reason this particular device is cranky. Looks like I need to go with a "real" level shifter.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • RaymanRayman Posts: 14,162
    edited 2008-04-10 16:14
    I posted a simple resistive circuit that might work in this thread:



    http://forums.parallax.com/showthread.php?p=711750
  • JonathanJonathan Posts: 1,023
    edited 2008-04-10 16:24
    Ray,

    Tried that. What gets me is that it reads OK once, on startup. Why not afterwards? I see another transistor/diode circuit from Phil in that thread, I'll try that one too.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-04-10 17:08
    This question has come up several times. There are circuits shown and referenced here that will do what you want.

    -Phil
  • JonathanJonathan Posts: 1,023
    edited 2008-04-10 17:14
    Phil,

    I have tried all the circuits I could find on the forums except for your transistor/diode one, which I plan to try when I get home. This device seems to be a little cranky for some reason. It works once (with several different circuits) upon startup, then fails all subsequent reads. I have great hopes for your circuit, I'll keep my fngers crossed.

    Thanks for all the help folks!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • Paul BakerPaul Baker Posts: 6,351
    edited 2008-04-10 19:23
    The fact that it works once makes me think it's a software issue.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • parskoparsko Posts: 501
    edited 2008-04-10 19:41
    Paul Baker (Parallax) said...
    The fact that it works once makes me think it's a software issue.

    I totally agree. I think you are chasing the wrong problem too. If it worked once, it should work ad infinitum. Check to make sure your code does not terminate itself somehow after the first read. Maybe your cog stops, or enters a recursive loop.

    Care to post your code??

    -Parsko
  • JonathanJonathan Posts: 1,023
    edited 2008-04-10 20:03
    Here is the code. Remember that it works fine at 3.3V. It's only at 5V that I get the one good reading than failure issue.
    CON
        _clkmode = xtal1 + pll16x
        _xinfreq = 5_000_000
        ' PropTerm
        #0, WHITE,CYAN,RED,PINK,BLUE,GREEN,YELLOW,GRAY
        
       ' ADC
       adcCLK       = 6     ' adcData = 7
       adcAddr      = %0110 ' Address pins both pulled high
       adcAddrMask  = %1001
       adcCmdMask   = %0111
    VAR
    word adcResult
    long adcACK
    byte adcChan
    OBJ
    term            : "PC_Interface" 
    adc             : "Basic_I2C_Driver"    
    PUB init
      term.start(31,30) ' Start Propterm object
      term.out(0)
      term.str(string("ADS7828 test...")) 'Splash screen
      wait_ms(1000)
      term.out(0)   ' Clear screen 
      
      adcChan := 7  ' Select adc channel to be read (0-7)
      adc.initialize(adcClK) ' Init adc
      repeat  ' Read channel and display results
        read_adc(adcChan)
        term.str(string("ADC result: "))
        term.dec(adcResult)
        wait_ms(1000)
        term.out(0)
    
    pub read_adc(channel) | adcByte
      ' Take channel and translate to the ADS7828 address code 
      channel := lookupz(channel:%1000,%1001,%1010,%1011,%1100,%1101,%1110,%1111) << 4|adcCmdMask
      adcByte :=adcAddrMask << 4 | adcAddr 
      adc.start(adcClK)                   
      adc.write(adcClK,adcByte) ' Send address and write bit
      adcByte := channel << 4 | adcCmdMask
      adc.write(adcClK,adcByte) ' Send channel and adc config
      adc.stop(adcClK)
      adc.start(adcClK)
      adcByte := adcAddrMask <<4 | adcAddr | 1
      adc.write(adcClK,adcByte) ' Send address and read bit
      adcresult.byte[noparse][[/noparse]1] := adc.read(adcClK,adcAck) ' Get result
      adcresult.byte[noparse][[/noparse]0] := adc.read(adcClK,adcAck)
      adc.stop(adcClK)  
    return
    PUB wait_ms(ms) ' Pause routine 
      waitcnt(cnt+(clkfreq / 1_000) * ms)
    RETURN
    PUB wait_us(us)
      waitcnt(cnt+(clkfreq / 1_000_000) * us)
    RETURN
    

    Thanks a ton for all the help!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • parskoparsko Posts: 501
    edited 2008-04-10 20:15
    Is term.out(0) a clear screen (maybe it displays once and is "clearing" the rest of the time)? When you say it works once, does it display then disappear? Or does it read once and display that value forever?

    also, I've read, but someone confirm, that if your pull-ups or downs are too strong or weak, then devices don't have enough time to react, or "overdrive" the "pull". Would that make sense here?
  • JonathanJonathan Posts: 1,023
    edited 2008-04-10 21:06
    Ok, it's getting closer but weirder...

    I took a look at the code and decided to try sticking the adc.initialize(adcCLK) line in the read_adc line. It will now read the ADC at continously 5V BUT...

    It only works with a 10k pullups to 3.3v on data and clk lines. I can put a series resistor on the CLK line but not on the data line. Yes, I know this is asking to burn out a Prop pin. I just wanted to see if it works. Another thing, the highest reading I can get is about 3700, in spite of the fact that the ADC channel is tied to +5Vdd. At 3.3V I get the full expected range.

    Now I need to go through and try all of the possible interface circuits.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • JonathanJonathan Posts: 1,023
    edited 2008-04-10 21:09
    Oh, and Parsko, it reads once and displays the same number forever.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • JavalinJavalin Posts: 892
    edited 2008-04-11 10:17
    Ah,

    I wonder:
    adcresult.byte := adc.read(adcClK,adcAck) ' Get result
    adcresult.byte[noparse][[/noparse]0] := adc.read(adcClK,adcAck)
    
    


    should be:

    adcresult.byte := adc.read(adcClK,adc#Ack)
    adcresult.byte[noparse][[/noparse]0] := adc.read(adcClK,adc#Nak)
    
    

    or even:

    long myResult
    
    myResult := adc.read(adcClK,adc#Nak) << 8 ' Get result
    myResult &= adc.read(adcClK,adc#Ack)
    

    (you'll need to check whether its ACK,NAK or NAK,ACK for your device)

    But I think this will expain the getting the same value - i.e. the chip isn't finishing the conversation, and/or the chip is holding i2c lines high/low

    Let us know how you get on.

    James

    Post Edited (Javalin) : 4/11/2008 12:25:02 PM GMT
  • JonathanJonathan Posts: 1,023
    edited 2008-04-11 13:35
    James,

    I'm not sure what the code you posted is trying to do. It does not comile as is. Any way you could explain (in small words) what it is supposed to do? I'm getting pretty tired of this adc, never had this kind of trouble with an i2c device.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • JavalinJavalin Posts: 892
    edited 2008-04-11 13:42
    Jonathan,

    If you're reading multiple bytes the i2c slave (the adc) needs an ACK or NAK as the 9th bit returned basically a "shall I continue" type message. if you don't send it you'll likely not end the "download process". In the ADC's datasheet its says (don't remember the page) the ACK/NAK requirement.

    The &= bit at the end was cause I wasn't sure about your ".byte" - so was wondering if that was part of the problem?

    Yeah - the MCP320X's are easy!

    James
  • parskoparsko Posts: 501
    edited 2008-04-13 00:46
    Jonathan,

    Did you figure this out, get distracted, or bail?

    -Parsko
  • JonathanJonathan Posts: 1,023
    edited 2008-04-13 14:07
    Parsko,

    Took a day off, I was (am) frustrated, and sometimes it's best to take a break.

    Bottom line, this device just seems cranky. I got two other i2c devices running fine. They work with almost any of the· 5v interface options. I don't know why this one is such a PITA. It does sorat work in 5v mode ATM, but it won't read full scale ie with 5v applied to an input I'm only getting a count of 3270 or so.

    I can't seem to find any other i2c adc in a tssop or dip package. Any suggestions? Or does anyone want to try to tame the ADS7828? I'd be happy to send one along, already mounted on a breakout board.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • JavalinJavalin Posts: 892
    edited 2008-04-13 16:32
    Jonathan,

    MCP3204 / MCP3208

    http://ww1.microchip.com/downloads/en/devicedoc/21298c.pdf

    Lots of example code in the Object exchange for them. Can be run on 2.7v to 5v

    J

    Update: - oh sorry - these are SPI...
  • RaymanRayman Posts: 14,162
    edited 2008-04-13 16:32
    Jonathan said...

    I can't seem to find any other i2c adc in a tssop or dip package. Any suggestions?

    There are two on this page:

    http://www.rayslogic.com/propeller/Programming/i2c/i2c.htm

    But, their datasheets both quote a minimum high state voltage of 0.7*Vdd, which would be 3.5 volts...· But, that's very close, so they might work that way...· Or, with that resistive circuit I posted...

    Post Edited (Rayman) : 4/13/2008 10:00:00 PM GMT
  • JonathanJonathan Posts: 1,023
    edited 2008-04-13 20:07
    Ray,

    I only find level shifters on the page you linked. I poked around on your site but didn't find the ADC's.

    Javalin, the part you linked is an SPI part. I'd really like to use i2c so I can use the already dedicated i2c pins on the prop.

    Thanks for all the help! No takers to try to tame the ADS7828? Not that I blame you. :-0

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • RaymanRayman Posts: 14,162
    edited 2008-04-13 21:57
    Oops... I was thinking I/O expanders... Sorry.
Sign In or Register to comment.