Shop OBEX P1 Docs P2 Docs Learn Events
How do I read more than 1 byte using I2CIN? — Parallax Forums

How do I read more than 1 byte using I2CIN?

CheetahCheetah Posts: 26
edited 2007-02-23 22:54 in BASIC Stamp
I'm interfacing to an ADS1000 chip using the BS2pe and I need to read 2 bytes of data from it.
The ADS1000 data sheet says that all I need to do is address the ads1000 for reading and just
read 2 bytes. I am able to one byte using the following pbasic statement:
I2CIN SDA, RdADS, 0, [noparse][[/noparse]result]




but I don't know how to read 2 bytes. Can someone explain to me how to read more than
one byte using I2CIN?

Thanks.

Comments

  • CheetahCheetah Posts: 26
    edited 2007-02-23 18:36
    BTW, in the code snippet above, the variable 'result' is defined as
    result  VAR word
    
  • DufferDuffer Posts: 374
    edited 2007-02-23 20:09
    Give this a try. From the·SERIN (works the same for I2CIN)·help file:

    serStr· VAR···· Byte(10)······················· ' Make a 10-byte array

    Main:
    · serStr(9) = 0·································· ·' Put 0 in last byte
    ··SERIN 1, 16468, [noparse][[/noparse]STR serStr\9]············' Get 9-byte string
    · DEBUG STR serString··························' Display the string
    · END



    Or in your case:

    Define a word variable (2 bytes) and:

    I2CIN 1, 16468, [noparse]/noparse]DEC2 [i]varname[/i
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-02-23 20:26
    Cheetah,

    If the device will send a 16-bit value it will most likely be sent as two bytes. You need to know how the device will send these 2 bytes (in what order, usually HIGHBYTE/LOWBYTE). Once you know that you can do something like.
    I2CIN SDA, $A1,EEprom_add.HIGHBYTE\EEprom_add.LOWBYTE,[noparse][[/noparse]value.HIGHBYTE, value.LOWBYTE] 
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • CheetahCheetah Posts: 26
    edited 2007-02-23 21:57
    Thanks guys. I'll try that. For some reason the search function of this board wasn't working today.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-02-23 22:49
    Cheetah, the search function on the Forums does not work well at all. Please see the following thread for a better search engine.

    http://forums.parallax.com/showthread.php?p=562370

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • CheetahCheetah Posts: 26
    edited 2007-02-23 22:54
    Thanks again.
Sign In or Register to comment.