I'm an Idiot! Can't get hi2cout to work!


Well-known member
I have never before tried picaxe I2C interfacing, and my first venture has proved discouraging.

I have a 24LC256 eeprom, 32k addresses, and I want to write to them sequentially. I thought I could do something like this:

I am using a 20m2

let w1=0
do while pinb.0=1
    readadc b.2,b0
    hi2cout w1,b0
    inc w1
This gives me a syntax error on the 'hi2cout w1,b0' line every time. I have tried putting different symbols in front of w1 (like % and #) but it still doesn't work.

I tried reading the command description of this command, and it didn't help me.

I did put a hi2csetup command at the beginning of my code.




another aspect to be aware of for EEPROMs is that when writing multiple bytes in a single Hi2cOut command, that the EEPROMs have an internal page buffer. In the case of the 24LC256 the page buffer holds 64 bytes (0 to 63). Some smaller capacity chips have smaller page and page buffer sizes.

If you write multiple bytes that cross a 64 byte boundary then wrap-around occurs and some data will be written at the start of the same 64-byte page that you first wrote in the higher bytes.

For example:
w0 = 61
hi2cout w0, (b0,b1,b2,b4, b5, b6)

This will be written into the EEPROM memory locations as follows:
location 61 - contents of b0
location 62 - contents of b1
location 63 - contents of b2
location 00 - contents of b3 (overwrites any existing data in address 00)
location 01 - contents of b4
location 02 - contents of b5

Hence when writing multiple bytes it is best to try and use multiples that fit into the 64 byte page structure (i.e. 8, 4 or 2)
otherwise your code needs to keep track on the locations and page boundaries.
If for example you have groups of 5 bytes then a page can hold 12 sets but then you must skip/jump 4 bytes to write into the next page of EEPROM.