Shop OBEX P1 Docs P2 Docs Learn Events
Problem reading second byte from 16bit ADC "ADS1110" — Parallax Forums

Problem reading second byte from 16bit ADC "ADS1110"

avionikerenavionikeren Posts: 64
edited 2011-06-02 13:42 in Propeller 1
I`m unable to read the second byte from the ADS1110, it returns only logic high`s (adc0[1] = 255)
Is there anyone with an idea?
PUB i2cRead |  i, i2cWriteData

   dira[adc1sda] ~~              
   dira[adc1scl] ~~             
   outa[adc1sda] := 1
   outa[adc1scl] := 1   
   outa[adc1sda] := 0
   outa[adc1scl] := 0

   'write
   i2cWriteData := $91 << 24 
   repeat 8          
     outa[adc1sda] := (i2cWriteData <-= 1) & 1         
     outa[adc1scl] := 1                           
     outa[adc1scl] := 0                           
                                                 
   dira[adc1sda] ~                             
   outa[adc1scl] := 1                  
   outa[adc1scl] := 0

   'read1
    i2cData := 0
    repeat 8
      outa[adc1scl] := 1
      i2cData := (i2cData << 1) | ina[adc1sda]
      outa[adc1scl] := 0
    dira[adc1sda] ~~
    outa[adc1scl] := 1
    outa[adc1sda] := 0
    outa[adc1scl] := 0
    dira[adc1sda] ~
    adc0[0] := i2cData 

    'read2
    i2cData := 0
    repeat 8
      outa[adc1scl] := 1
      i2cData := (i2cData << 1) | ina[adc1sda]
      outa[adc1scl] := 0
    dira[adc1sda] ~~
    outa[adc1scl] := 1
    outa[adc1sda] := 0
    outa[adc1scl] := 0
    adc0[1] := i2cData

    outa[adc1scl] := 1
    outa[adc1sda] := 1

Comments

  • avionikerenavionikeren Posts: 64
    edited 2011-06-02 09:37
    Please help me with this, I`m totally stuck...
  • AribaAriba Posts: 2,690
    edited 2011-06-02 11:14
    I think the problem is how you drive the ACKs after a Read. OUTA[SDA] is high when you set the clock high and then you drive it to Low while SCL is High -> that is a new start condition.

    You should anyway not drive the SDA pin High. For that I2C uses a pullup. To output a HIGH you set dira=0 and to output a LOW you set dira to 1 (and the outa bit stays always Low).

    Here is a untested changed version of your Read methode:
    CON
       OUTP  = 1
       HIGHZ = 0
       LOWZ  = 1
    
    PUB i2cRead |  i, i2cWriteData
    
       outa[adc1scl] := 1   
       outa[adc1sda] := 0
       dira[adc1sda] := HIGHZ             
       dira[adc1scl] := OUTP             
       dira[adc1sda] := LOWZ    'start condition
       outa[adc1scl] := 0
    
       'write
       i2cWriteData := $91 >< 8 
       repeat 8          
         dira[adc1sda] := i2cWriteData ^ 1 & 1
         i2cWriteData >>= 1         
         outa[adc1scl] := 1                           
         outa[adc1scl] := 0                           
                                                     
       dira[adc1sda] := HIGHZ   'ack from ADC                         
       outa[adc1scl] := 1
       'read ACK here if necessary                  
       outa[adc1scl] := 0
    
       'read1
        i2cData := 0
        repeat 8
          outa[adc1scl] := 1
          i2cData := (i2cData << 1) | ina[adc1sda]
          outa[adc1scl] := 0
        dira[adc1sda] := LOWZ    'ACK
        outa[adc1scl] := 1
        outa[adc1scl] := 0
        dira[adc1sda] := HIGHZ
        adc0[0] := i2cData 
    
        'read2
        i2cData := 0
        repeat 8
          outa[adc1scl] := 1
          i2cData := (i2cData << 1) | ina[adc1sda]
          outa[adc1scl] := 0
        dira[adc1sda] := LOWZ    'ACK
        outa[adc1scl] := 1
        outa[adc1scl] := 0
        adc0[1] := i2cData
    
        outa[adc1scl] := 1       'stop condition
        dira[adc1sda] := HIGHZ
    
    The SCL line is driven High and Low here so you need no pullup on SCL. But SDA needs one.

    Andy
  • avionikerenavionikeren Posts: 64
    edited 2011-06-02 13:42
    Thank you very much!!
    The changes you made to the code works perfect.
Sign In or Register to comment.