Shop OBEX P1 Docs P2 Docs Learn Events
I2C not working for me..see if you can help? — Parallax Forums

I2C not working for me..see if you can help?

doughboydoughboy Posts: 12
edited 2008-06-13 23:55 in BASIC Stamp
trying to do a simple write read to a register code below----

'Pins
'
SDA PIN 0 ' P0 Serial bidirectional data line on the AD7745 [noparse][[/noparse]MUST BE PIN 0 OR 8]
SCL PIN 1 ' P1 Serial clock line on the AD7745
RDY PIN 2 ' P2 RDY pin on the AD7745 goes low when new data is ready


regdata VAR Byte
regdata = $00


INPUT SDA
INPUT SCL
LOW SDA
INPUT RDY
I2COUT SDA,$90,$0A,[noparse][[/noparse]$FF]
I2CIN SDA,$91,$0A, [noparse][[/noparse]STR regdata \8]
DEBUG BIN8 regdata,CR





the debug never gives me what I am writing to the register....SDA and SCLk are pulled up high......any help would be great!
btw the device works that im trying to talk to as it has usb as well

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-06-12 21:53
    This ought to work except that the I2CIN input list should not be "STR regdata \ 8". It should be just "regdata". The length operand "\8" is in terms of bytes, not bits and regdata is only a single byte. I'm not sure this change will fix it, but it does need to be corrected.

    The register you're writing to is the configuration register. Is this what you want?
  • doughboydoughboy Posts: 12
    edited 2008-06-13 06:23
    sure, it was simply the lowest addressable register that was read and write..of course its not workng though! ugh it would apear to read the $00 register every time.....as it comes up with its default value in the debug.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2008-06-13 12:30
    Syntax: I2COUT Pin, SlaveID, {Address {\LowAddress},} [noparse][[/noparse]OutputData]

    I2COUT's Pin argument is 0 or 1 and that determines which set of pins to use for SDA and SCL already (P0 & P1 or P8 & P9, respectively.)·

    So, the SDA and SCL pin declarations are unnecessary.
    SDA PIN 0··X ' P0 Serial bidirectional data line on the AD7745
    SCL PIN 1··X··' P1 Serial clock line on the AD7745
    I/O direction for SDA·is handled automatically,·given the context (I2CIN or I2COUT).
    So, the INPUT commands are unnecessary.
    INPUT SDA· X
    INPUT SCL· X

    LOW SDA· · X
    I don't know what you're using LOW SDA for.
  • doughboydoughboy Posts: 12
    edited 2008-06-13 16:06
    just initializing it to something
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2008-06-13 23:55
    The program lines that you have posted do not even tokenize because of things like:
    I2COUT SDA,$90,$0A,[noparse][[/noparse]$FF]
    I2CIN SDA,$91,$0A, [noparse][[/noparse]STR regdata \8]
    You "could" do that if you had declared SDA as a VARiable or CONstant
    These two examples tokenize --

    ' {$STAMP BS2p}
    ' {$PBASIC 2.5}
    regdata VAR Byte
    regdata = $00
     
    RDY PIN 2 ' P2 RDY pin
     
    Start:
     I2COUT 0,$90,$0A,[noparse][[/noparse]$FF]
     I2CIN 0,$91,$0A, [noparse][[/noparse]regdata]
     DEBUG BIN8 regdata,CR
     PAUSE 1000
     GOTO Start
     
     
    ' {$STAMP BS2p}
    ' {$PBASIC 2.5}
    regdata VAR Byte
    regdata = $00
     
    RDY PIN 2 ' P2 RDY pin
     
    Start:
     I2COUT 0,$90,$0A,[noparse][[/noparse]$FF]
     IF RDY = 0 THEN I2CIN 0,$91,$0A, [noparse][[/noparse]regdata]
     DEBUG BIN8 regdata,CR
     PAUSE 1000
     GOTO Start
    

    
    

    Post Edit -- An AD7745 has a 24-bit (which is a little more than a Byte) output.

    ' {$STAMP BS2p}
    ' {$PBASIC 2.5}
     
    regdata VAR Byte (3)              ' *************
    regdata = $00
     
    RDY PIN 2 ' P2 RDY pin
     
    Start:
     I2COUT 0,$90,$0A,[noparse][[/noparse]$FF]
     I2CIN 0,$91,$0A, [noparse][[/noparse]STR regdata\3] ' *************
    
     DEBUG BIN8 regdata (0),CR
     DEBUG BIN8 regdata (1),CR
     DEBUG BIN8 regdata (2),CR
    
     PAUSE 1000
     GOTO Start
    

    Post Edited (PJ Allen) : 6/14/2008 12:55:50 AM GMT
Sign In or Register to comment.