Shop OBEX P1 Docs P2 Docs Learn Events
I2C — Parallax Forums

I2C

ArchiverArchiver Posts: 46,084
edited 2004-05-20 03:51 in General Discussion
Found some BSI and BSII I2C code at www.hth.com (page is Swedish).

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2000-08-29 22:50
    hello,

    has anyone experience with the pcf8573, pcf8574, pcf8583,pcf8584 or saa1064?
    Want to connect them to a basicstamp, haven'figured out how yet!

    thanks pieter-jan
    _________________________________________________________________________
    Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.

    Share information about yourself, create your own public profile at
    http://profiles.msn.com.
  • ArchiverArchiver Posts: 46,084
    edited 2000-10-03 14:38
    hello all,

    can't get my code working with i2c, hte basics of the code are good, because
    when i test it with a 24c65 it works fine.

    can anybody take a look into it, is this code to fast for the i2c protocol?

    anyway, it's different from peter anderson code of the i2c, think it does
    the same...

    all info is welcome, i'm a littlebit desperate [noparse];)[/noparse]


    'i2c subroutines
    'pcf8583



    'VARIABELEN
    i2data var byte
    i2datahi var i2data.highnib
    i2datalo var i2data.lownib
    i2dt con 0
    i2clk con 1
    i2ack var bit
    i2memwr con %10100000
    i2memrd con %10100001
    temp1 var byte
    temp1hi var temp1.highnib
    temp1lo var temp1.lownib
    temp2 var nib
    memtop con 150
    i var word


    TEST:
    'just a read test, i'm not writing yet
    for i=1 to 50000
    gosub lees2
    pause 100
    next
    end

    lees2:
    gosub i2start
    i2data = %10100000
    gosub i2tx
    gosub ackrx
    i2data = %00000000
    gosub i2tx
    gosub ackrx
    gosub i2start
    i2data = %10100001
    gosub i2tx
    gosub ackrx
    'this is the hard way,
    'according to me a start and direct
    '10100001 must do the trick also
    'get strange values with this program
    gosub i2rx
    temp1 =i2data
    gosub acktx
    debug "A",dec3 ? temp1,cr
    gosub i2rx
    temp1 =i2data
    debug "B",dec3 ? temp1,cr
    gosub i2rx
    temp1 =i2data
    debug "C",dec3 ? temp1,cr
    gosub i2rx
    temp1 =i2data
    debug "D",dec3 ? temp1,cr
    gosub i2rx
    temp1 =i2data
    debug "E", dec3 ? temp1,cr
    gosub i2rx
    temp1 =i2data
    debug "F",dec3 ? temp1,cr
    gosub i2rx
    temp1 =i2data
    debug "G",dec3 ? temp1,cr
    gosub i2rx
    temp1 =i2data
    ' gosub acktx
    debug "H", dec3 ? temp1,cr
    gosub i2stop
    return


    I2START:
    high i2dt
    high i2clk
    low i2dt
    return

    I2STOP:
    low i2dt
    high i2clk
    high i2dt
    return

    I2TX:
    'transmit data
    shiftout i2dt,i2clk,1,[noparse][[/noparse]i2data]
    return

    I2RX:
    shiftin i2dt,i2clk,0,[noparse][[/noparse]i2data]
    return

    ACKTX:
    shiftout i2dt,i2clk,1,[noparse][[/noparse]%0\1]
    return

    ACKRX:
    shiftin i2dt,i2clk,0,[noparse][[/noparse]i2ack\1]
    if i2ack=0 then ret
    debug "ack failed"
    debug hex ?i2data
    nap 7
    return


    RET:
    return

    thanks from pieter-jan!!
    _________________________________________________________________________
    Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.

    Share information about yourself, create your own public profile at
    http://profiles.msn.com.
  • ArchiverArchiver Posts: 46,084
    edited 2000-10-03 19:46
    hello all,

    Can anyone please look at this code, according to me it must work, with a
    littlebit of adjustments it works fine with the 24c65 eeprom. Right now i
    think i work according specs of the i2c, but quiet different of peter
    anderson's code.

    Any help is appreciated!!

    the chip i'm using has 8 registers that i want to read, it seems two
    readings work fine, rest looks like garbage. with a different start address
    that two looks fine, rest looks garbage etcetera

    many thanks pieter-jan

    here is the code...

    'i2c subroutines
    'pcf8583



    'VARIABELEN
    i2data var byte
    i2datahi var i2data.highnib
    i2datalo var i2data.lownib
    i2dt con 0
    i2clk con 1
    i2ack var bit
    i2memwr con %10100000
    i2memrd con %10100001
    temp1 var byte
    temp1hi var temp1.highnib
    temp1lo var temp1.lownib
    temp2 var nib
    memtop con 150
    i var word


    TEST:
    for i=1 to 50000
    gosub lees2
    pause 100
    next
    end

    lees2:
    gosub i2start
    i2data = %10100000
    gosub i2tx
    gosub ackrx
    i2data = %00000000
    gosub i2tx
    gosub ackrx
    gosub i2start
    i2data = %10100001
    gosub i2tx
    gosub ackrx
    'this is the hard way,
    'according to me a start and direct
    '10100001 must do the trick also
    'get strange values with this program
    gosub i2rx
    temp1 =i2data
    gosub acktx
    debug "A",dec3 ? temp1,cr
    gosub i2rx
    temp1 =i2data
    debug "B",dec3 ? temp1,cr
    gosub i2rx
    temp1 =i2data
    debug "C",dec3 ? temp1,cr
    gosub i2rx
    temp1 =i2data
    debug "D",dec3 ? temp1,cr
    gosub i2rx
    temp1 =i2data
    debug "E", dec3 ? temp1,cr
    gosub i2rx
    temp1 =i2data
    debug "F",dec3 ? temp1,cr
    gosub i2rx
    temp1 =i2data
    debug "G",dec3 ? temp1,cr
    gosub i2rx
    temp1 =i2data
    ' gosub acktx
    debug "H", dec3 ? temp1,cr
    gosub i2stop
    return


    I2START:
    high i2dt
    high i2clk
    low i2dt
    return

    I2STOP:
    low i2dt
    high i2clk
    high i2dt
    return

    I2TX:
    'transmit data
    shiftout i2dt,i2clk,1,[noparse][[/noparse]i2data]
    return

    I2RX:
    shiftin i2dt,i2clk,0,[noparse][[/noparse]i2data]
    return

    ACKTX:
    shiftout i2dt,i2clk,1,[noparse][[/noparse]%0\1]
    return

    ACKRX:
    shiftin i2dt,i2clk,0,[noparse][[/noparse]i2ack\1]
    if i2ack=0 then ret
    debug "ack failed"
    debug hex ?i2data
    nap 7
    return


    RET:
    return

    _________________________________________________________________________
    Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.

    Share information about yourself, create your own public profile at
    http://profiles.msn.com.
  • ArchiverArchiver Posts: 46,084
    edited 2000-10-04 02:53
    Note that the two states for the I2C should be a hard zero (GRD) and
    high impedance which I accomplish by making the pin an input. The
    high impedance permits the slave to pull the bus low.

    But, if this code is partially working for you, the problem may be in
    failing to ACK after the receipt of the each byte. I have entered
    these in CAPS below.

    Note that a NACK is sent prior to the STOP to inicate to the slave,
    there is no more.

    Peter H. Anderson, http://www.phanderson.com/stamp
    Homebrew BS2


    > gosub i2rx
    > temp1 =i2data
    > gosub acktx
    > debug "A",dec3 ? temp1,cr
    > gosub i2rx
    > temp1 =i2data
    GOSUB ACKTX
    > debug "B",dec3 ? temp1,cr
    > gosub i2rx
    > temp1 =i2data
    GOSUB ACKTX
    > debug "C",dec3 ? temp1,cr
    > gosub i2rx
    > temp1 =i2data
    GOSUB ACKTX
    > debug "D",dec3 ? temp1,cr
    > gosub i2rx
    > temp1 =i2data
    GOSUB ACKTX
    > debug "E", dec3 ? temp1,cr
    > gosub i2rx
    > temp1 =i2data
    GOSUB ACKTX
    > debug "F",dec3 ? temp1,cr
    > gosub i2rx
    > temp1 =i2data
    GOSUB ACKTX
    > debug "G",dec3 ? temp1,cr
    > gosub i2rx
    > temp1 =i2data
    GOSUB ACKRX
    > debug "H", dec3 ? temp1,cr
    > gosub i2stop
    > return
    >
    >
    > I2START:
    > high i2dt
    > high i2clk
    > low i2dt
    > return
    >
    > I2STOP:
    > low i2dt
    > high i2clk
    > high i2dt
    > return
    >
    > I2TX:
    > 'transmit data
    > shiftout i2dt,i2clk,1,[noparse][[/noparse]i2data]
    > return
    >
    > I2RX:
    > shiftin i2dt,i2clk,0,[noparse][[/noparse]i2data]
    > return
    >
    > ACKTX:
    > shiftout i2dt,i2clk,1,[noparse][[/noparse]%0\1]
    > return
    >
    > ACKRX:
    > shiftin i2dt,i2clk,0,[noparse][[/noparse]i2ack\1]
    > if i2ack=0 then ret
    > debug "ack failed"
    > debug hex ?i2data
    > nap 7
    > return
    >
    >
    > RET:
    > return
  • ArchiverArchiver Posts: 46,084
    edited 2000-10-04 12:44
    hello all,

    I'm not sure that i use the high speed bus, it's not named at the datasheet
    (as far as i know)

    The bs2 is the master, so i am using single master.

    if i have to extend the clock low, then shiftout isn't working anymore?
    (shiftout has a timing i can't program?) and i should use peter andersons
    code...

    thanks

    pieter-jan


    _________________________________________________________________________
    Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.

    Share information about yourself, create your own public profile at
    http://profiles.msn.com.
  • ArchiverArchiver Posts: 46,084
    edited 2001-05-08 20:27
    hello,

    has anyone ever written a program to read/write data to/from a chipcard
    (e.g. bank account card) via the I2C-Bus provided by the Stamp IIP? I know i
    cannot write money on it :-) but I know that you still can read and write
    on them...

    Thanx for help,

    uli


    www.raumschiff-interactive.de
  • ArchiverArchiver Posts: 46,084
    edited 2004-05-19 06:14
    Does anyone know how far a stamp2 can be from an I2C peripheral unit?

    Michael
  • ArchiverArchiver Posts: 46,084
    edited 2004-05-19 10:51
    In a message dated 5/19/2004 1:45:29 AM Eastern Daylight Time,
    magzi@p... writes:


    > Does anyone know how far a stamp2 can be from an I2C peripheral unit?
    >

    Do you mean how far and still work?

    Sid


    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2004-05-19 17:03
    In a message dated 5/19/2004 3:40:54 PM Eastern Daylight Time,
    magzi@p... writes:


    > yes that's what I mean
    >
    >

    I have run peripherals 40 feet on 22 gauge wire. My guess is that you could
    probably go 100 feet with 20 gauge. Stranded would be better than solid.

    Sid


    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2004-05-19 20:35
    --- In basicstamps@yahoogroups.com, Newzed@a... wrote:
    > In a message dated 5/19/2004 1:45:29 AM Eastern Daylight Time,
    > magzi@p... writes:
    >
    >
    > > Does anyone know how far a stamp2 can be from an I2C peripheral unit?
    > >
    >
    > Do you mean how far and still work?
    >
    > Sid

    yes that's what I mean
  • ArchiverArchiver Posts: 46,084
    edited 2004-05-20 03:51
    I think it depends mostly on what pullup resistor values you use. Short runs
    (same PCB) use a 10k, longer runs use 4.7k, really long runs could use
    lower. You need supply a minimum amount of current (check datasheet) and the
    wire resistance adds to the pullup resistance, possible making the current
    to low to be read correctly.

    Of course RFI becomes a problem with longer runs - may need shielded cable
    etc.

    >
    Original Message
    > From: Newzed@a... [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=lyZLxYUML688fOw80zzrHNdKfAcuyYuZOBTwvFtFfzz58TuwM_LupwcrTtTmRLxsR2FMhMywAg]Newzed@a...[/url
    > Sent: May 19, 2004 1:03 PM
    > To: basicstamps@yahoogroups.com
    > Subject: Re: [noparse][[/noparse]basicstamps] Re: i2c
    >
    >
    > In a message dated 5/19/2004 3:40:54 PM Eastern Daylight Time,
    > magzi@p... writes:
    >
    >
    > > yes that's what I mean
    > >
    > >
    >
    > I have run peripherals 40 feet on 22 gauge wire. My guess is
    > that you could
    > probably go 100 feet with 20 gauge. Stranded would be better than solid.
    >
    > Sid
    >
    >
    > [noparse][[/noparse]Non-text portions of this message have been removed]
    >
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed. Text in the
    > Subject and Body of the message will be ignored.
    >
    > Yahoo! Groups Links
    >
    >
    >
    >
    >
    >
Sign In or Register to comment.