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

i2c 3.3V to 5V

2»

Comments

  • JavalinJavalin Posts: 892
    edited 2008-04-14 07:16
    >>Or does anyone want to try to tame the ADS7828? I'd be happy to send one along, already mounted on a breakout board.

    Jonathan - Im game. If I can get it to play i'll add to the i2cObjectv2 library!

    Im in the UK so shipping costs (assuming your USA) might make this unworkable...

    Still - PM me if you want.

    J
  • JonathanJonathan Posts: 1,023
    edited 2008-04-14 14:19
    Oh, it can't be that much, I'll send it slow boat. I'll PM ya.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • JavalinJavalin Posts: 892
    edited 2008-04-14 15:22
    Hi Jonathan,

    Try this.· Cleaned up the code - its force to channel 7 at present for testing.· You had a few errors that I found on close inspection and reading the datasheet.

    I've set it up (so i can compile it) to use a serial debug object on the programming pins at 115_200 baud.

    See how you get on - if it works it'll save the postage!

    James

    edit -> ZIP updated with *working* code.

    Post Edited (Javalin) : 4/16/2008 3:21:28 PM GMT
  • JonathanJonathan Posts: 1,023
    edited 2008-04-15 13:44
    Javalin,

    Spent yesterday chainsawing trees that fell in my garden this winter. I'll try to give it a shot this morning, but I have another chainsaw day ahead. Thanks a TON for taking the time, and I'll let you know.

    Thanks!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • JonathanJonathan Posts: 1,023
    edited 2008-04-15 14:41
    Javalin,

    Yook a quick shot at using your code. It doesn't work right off the bat. It always returns 0. I tried using your:

    adcresult := i2cObject.read(i2cClK,i2cObject#Ack) << 8
    adcresult &= i2cObject.read(i2cClK,i2cObject#Nak)

    in my code, but I still get a 0. I tried using my equivilent code snip in your code, still reads a 0. So, your init/address/command code won't load the variable my way. My init/address/command code won't load the variable your way. So at a guess, there are issues in both the init/address/command delivery and the receiving code.

    Didn't have time to look at it on the scope. My buddy just arrived with his chainsaw, so it's time to get bucking firewood for next winter.

    Thanks so much for the help!!! I'll get back to it this evening.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • JavalinJavalin Posts: 892
    edited 2008-04-16 07:31
    Hi,

    Minor mistake in the previous zip file....· The function passes back a 0 into the variable it sets. Oops.

    Corrected in the attached.

    Let me know how you get on

    James

    Post Edited (Javalin) : 4/16/2008 10:23:39 AM GMT
  • JonathanJonathan Posts: 1,023
    edited 2008-04-16 15:20
    James,

    Still no joy. I have yet another long day ahead, I was too beat to play last night. I wonder why it doesn't work at all. I'll take a look this evening, I shouldn't (hopefully) be so beat.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • JonathanJonathan Posts: 1,023
    edited 2008-04-18 16:56
    Muhahaha! Got it working!
    It was indeed in the software. I obviously needed to take a few days off it. I just started again this morning from scratch and now it works. The readins are very stable, even on a breadboard. I am using Beau's i2c level shifter circuit (transistor/diode). Here is the code that did it.
    CON
        _clkmode = xtal1 + pll16x
        _xinfreq = 5_000_000
        ' PropTerm
        #0, WHITE,CYAN,RED,PINK,BLUE,GREEN,YELLOW,GRAY
        
       ' ADC
       adcCLK       = 4     ' adcData = 7
       adcAddr      = %0110 ' Address pins both pulled high
       adcAddrMask  = %1001
       adcCmdMask   = %0111
    VAR
    long 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.initialize(adcClK)
      adc.start(adcClK)                   
      adc.write(adcClK,adcByte) ' Send address and write bit
      adcByte := adcCmdMask << 4 | channel
      adc.write(adcClK,adcByte) ' Send channel and adc config
      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
    
    

    James, thanks so much for all your help. I would have thrown my hands up and given up in disgust. Would you still like an ADC? I would be very happy to mail you one for all your efforts. I got 'em as samples, so dont be shy. [noparse]:)[/noparse]

    Thanks to evryone else as well. I had given up on this device.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • parskoparsko Posts: 501
    edited 2008-04-18 16:57
    What's your "10-word-or-less" explanation to what was wrong?
  • JonathanJonathan Posts: 1,023
    edited 2008-04-18 17:04
    Parsko,

    Hmm, so many mistakes it will take me over the 10 word limit. [noparse]:)[/noparse]

    Read bit not in the right place and single/differential mode not being set right. The channel bits were not being masked and shifted correctly. There may have been other errors as well, I went through so many changes I lost track. Not all of the errors were present at once, but looking through all my differnt version I found all these errors at one time or another. I was also putting in an extra "stop" command that wasn't needed, but doesn't seem to matter.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • JonathanJonathan Posts: 1,023
    edited 2008-04-18 18:39
    Hehe, add two more errors. [noparse]:)[/noparse]
    Had an error in the channel lookup code, as well as an extra and erronous bit shift. It really works now, on all channels as it should. [noparse]:)[/noparse] Just thought I'd update the code here in case some poor soul was foolish enough to try my code. [noparse]:)[/noparse]
    CON
        _clkmode = xtal1 + pll16x
        _xinfreq = 5_000_000
        ' PropTerm
        #0, WHITE,CYAN,RED,PINK,BLUE,GREEN,YELLOW,GRAY
        
       ' ADC
       adcCLK       = 4     ' adcData = 7
       adcAddr      = %0110 ' Address pins both pulled high
       adcAddrMask  = %1001
       adcCmdMask   = %0100
    VAR
    long adcResult
    long adcACK
    byte adcChan, byte1,byte2,byte3
    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 := 6  ' 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)
        set_pos(0,1)
        term.bin(byte2,8)
        wait_ms(1000)
        term.out(0)
    
    pub read_adc(channel) | adcByte
      ' Take channel and translate to the ADS7828 address code 
      channel := lookupz(channel:%1000,%1100,%1001,%1101,%1010,%1110,%1011,%1111) << 4 | adcCmdMask
      adcByte :=adcAddrMask << 4 | adcAddr
      adc.initialize(adcClK)
      adc.start(adcClK)                   
      adc.write(adcClK,adcByte) ' Send address and write bit
      adcByte := channel << 4 | adcCmdMask
      adc.write(adcClK,channel) ' Send channel and adc config
      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
    PRI set_pos(px, py)
      term.out(10)
      term.out(px)
      term.out(11)
      term.out(py)
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • parskoparsko Posts: 501
    edited 2008-04-18 18:41
    Jonathan,

    thanks for the update. It's nice to know what was done to fix the problem.

    It's nice when it works the way you want it, right?!?!

    -Luke
  • JavalinJavalin Posts: 892
    edited 2008-04-19 07:24
    Hi Jonathan,

    Yeah if you don't mind. Might be useful on a future toy to have an i2c adc.

    Glad you got it working..!

    smile.gif

    J
  • JonathanJonathan Posts: 1,023
    edited 2008-04-19 17:22
    I'll mail it out this week. And Luke, yeah it is nice when it works out. [noparse]:)[/noparse] I'm quite pleased the the performance of this device now, it is reading my barometric pressure sensor very nicely.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • JavalinJavalin Posts: 892
    edited 2008-04-30 08:56
    Jonathan,

    Recieved the chip today - many thanks!

    James
  • JonathanJonathan Posts: 1,023
    edited 2008-04-30 12:50
    James,

    Holy cow! I just sent it a few days ago, it made a quck journey across the pond! You are very welcome, and I thank you for your help in mastering the chip. Let us know how you like it when you try it. Mine is integrated into my project and using the dedicated i2c pins of the protoboard, and working very nicely.

    Jonathan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • JavalinJavalin Posts: 892
    edited 2008-05-07 11:16
    Jonathan,

    I had a play at the weekend with the i2c ADC you sent me.· I thought - Ah this will only take 30mins to adapt your code and include a "james's" version in the i2cObjectv2 library.

    I couldn't get the chip working - I seem to get all high results.· i.e. 3000, there is some variation as pulling the adc inputs to 5v shows 4096 sometimes.

    Attached JPG of the connections I think I am using - I will double check at home.

    I've tried your code too and I don't get any more success.· I think its a hardware issue at present....· Might be an i2c clock-stretching jobby thou - but attacking the easiest bits first....

    Any thoughts?

    Cheers,

    James

    edit -> updated the schematic.

    Post Edited (Javalin) : 5/7/2008 11:28:51 AM GMT
    844 x 561 - 30K
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2008-05-07 13:10
    I think you need to fix A0 and A1 at either GND or VDD.
    These are probably part of the slave address.

    regards peter
  • JavalinJavalin Posts: 892
    edited 2008-05-07 13:15
    Hi peter,

    Not shown in the diagram, but A0 is pulled to VDD (im using a changed address) but A1 is floating. I'll try pulling A1 to GND.

    Cheers,

    James
  • JonathanJonathan Posts: 1,023
    edited 2008-05-07 13:18
    James,

    In my code the address pins are set high. As well, the VREF pin has 5V on it. I am using Beau's level shifter circuit. Are you using the dedicated I2C pins from the Prop? If not, you don't need the level shifter.
    [size=2][code]
    adcCLK       = 28     
      adcAddr      = %0110 ' Address pins both pulled high
      adcAddrMask  = %1001 ' First four bits always 1001
      adcCmdMask   = %0100 ' Use +vref, converter left on
    

    pub read_adc(channel) | adcByte
      ' Take channel and translate to the ADS7828 address code 
      channel := lookupz(channel:%1000,%1100,%1001,%1101,%1010,%1110,%1011,%1111) << 4 | adcCmdMask
      adcByte :=adcAddrMask << 4 | adcAddr | 0  ' load address and write bit
      adc.initialize(adcClK)' Init adc
      adc.start(adcClK)                   
      adc.write(adcClK,adcByte) ' Send address and write bit
      adc.write(adcClK,channel) ' Send channel and adc config
      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
    

    [/code][/size]

    The above code has been chugging along and working fine for the last couple of weeks.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • JonathanJonathan Posts: 1,023
    edited 2008-05-11 13:55
    James,

    Odd, I made a post in reply to the above days ago, and I have it in my inbox but I don't see it here. Any progress?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • JavalinJavalin Posts: 892
    edited 2008-05-11 16:47
    Hiya

    No - been busy in the end of this week.

    I'll try this week to get it working...

    J
Sign In or Register to comment.