I2CIN and I2COUT a 16 bit number (Word)
Sunzt
Posts: 9
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?
****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
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).