Shop OBEX P1 Docs P2 Docs Learn Events
I2CIN I2COUT & array — Parallax Forums

I2CIN I2COUT & array

TumblerTumbler Posts: 323
edited 2009-10-12 05:37 in BASIC Stamp
FOR i = 0 TO 10
  add = (i * 16)
  DEBUG CR,DEC3 add," :"
  FOR j = 0 TO 15
    add = (i * 16)+j
    I2CIN SDA, $A1,add.HIGHBYTE\add.LOWBYTE, [noparse][[/noparse]arr]
    DEBUG DEC3 arr,","
    'PAUSE 20
  NEXT
NEXT

This code reads a block eeprom data. But is it possible to read an array(16bytes) so i can read this block with only 1 for-next?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-07 17:27
    Read the description of the STR "formatter" in the chapters on the I2CIN and I2COUT statements in the Stamp Basic Manual.
  • TumblerTumbler Posts: 323
    edited 2009-10-07 17:40
    [noparse][[/noparse]STR arr\16]

    Thank you Mike
  • TumblerTumbler Posts: 323
    edited 2009-10-11 10:09
    This code:
    
    
    'arr is filled with zero's 
    FOR i = 0 TO 10
      eeprom_add = (i * 16)
      I2COUT SDA, $A0,eeprom_add.HIGHBYTE\eeprom_add.LOWBYTE, [noparse][[/noparse]STR arr]
      PAUSE 20
    NEXT
    

    clears a part of an eeprom memor. However, When i make a dump:

    
    
    address00-15   cleared
    16-31   not cleared
    32-47   cleared
    48-63   not cleared
    ...
    

    I have searched here on this forum, the BS manual·and the datasheet (24lc128) but couldn't find anything about this problem.
    Since i have no 4k7 resistors, i have used 10k resistors. Maybe this is the prob?

    regards
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2009-10-11 12:06
    Tumbler said...
    Since i have no 4k7 resistors, i have used 10k resistors. Maybe this is the prob?
    Well, sometimes you just have to work with what you've got: Two 10K resistors in parallel are 5K and that's close enough to 4.7K to find out (but it's not likely your trouble.)
  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-11 14:37
    If you don't put the "\16" after the "arr", the STR stops at the first zero byte (well documented in the manual). In your case, the first zero byte is the first byte and nothing gets written at all. I can only assume that the EEPROM was already cleared in the pattern you saw.
  • TumblerTumbler Posts: 323
    edited 2009-10-11 15:24
    You're right Mike about the manual.
    ..., otherwise, characters will be sent up to the first byte equal to 0 or ...
    


    I have to test it this evening, when i'm at home. But i don't think that's the problem. I'm sure all addresses·are filled with 255 (dec)·
  • TumblerTumbler Posts: 323
    edited 2009-10-11 19:13
    Seems like the 128 and 256 use the same instructions, or do i miss something. eyes.gif

    Huh Mike, did you delete your last post here?
  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-11 19:17
    I misread the datasheet, made some comments, then retracted the message when I realized it was wrong.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2009-10-11 21:41
    The data at each location is a Byte (no Words.)·

    You can I2COUT bytes from an array --

    I2COUT SDA, $A0, 0, [noparse][[/noparse]STR memloc\16]· ' 00·= start_addr for 0-15

    and you can I2CIN bytes to an array --

    I2CIN SDA, $A0, 16, [noparse][[/noparse]STR memloc\16]··'·16·= start_addr for 16-31

    and all without a FOR...NEXT, when you do an STR the Stamp takes over and handles the rest.
  • TumblerTumbler Posts: 323
    edited 2009-10-12 05:37
    Well done Mike, the '\16' works perfectly.

    PJ Allen: i'm using bytes. (array)
Sign In or Register to comment.