Shop OBEX P1 Docs P2 Docs Learn Events
I2CIN and I2COUT a 16 bit number (Word) — Parallax Forums

I2CIN and I2COUT a 16 bit number (Word)

SunztSunzt Posts: 9
edited 2007-03-29 03:39 in BASIC Stamp
I'm trying to store and read a Word type into my NVRAM, but I'm not sure how I would do that correctly with the I2C commands. I'm using a BS2px and PBASIC 2.5.

****EXAMPLE CODE*****

count VAR Word

count = 300

I2COUT MemIO, $A1, 0\0, [noparse][[/noparse]count]
I2CIN MemIO, $A0, 0\0, [noparse][[/noparse]count]
DEBUG count

**********************

Will the above debug display 300 or only 300>>8? If I want to write to the next empty NVRAM address I think that I have to use address 2, correct?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-03-29 00:14
    I2COUT like SEROUT only provides for byte values. If you want to send a word value, you have to split it up explicitly like
    I2COUT MemIO,$A1,0\0,[noparse][[/noparse]count.lowbyte,count.highbyte]
    or
    I2CIN MemIO,$A0,0\0,[noparse][[/noparse]count.lowbyte,count.highbyte]
    
    


    In what you wrote, you'll see only 300>>8. Most EEPROMs use what's called paged mode with page sizes like 64, 128, or 256 bytes depending on the EEPROM size and the manufacturer. If you have a single I2COUT statement with multiple data bytes all within a page, the write will work as you expect. The write address wraps around at the page boundary, so a write that spans two pages won't work (it'll wrap around to the beginning of the page). You also need a 5ms pause after the write operation for the EEPROM to finish. It won't respond to the I2CIN or another I2COUT for several milliseconds (up to 5ms).
  • SunztSunzt Posts: 9
    edited 2007-03-29 03:39
    Awesome, thanks!
Sign In or Register to comment.