It seems that there is nothing wrong with the procedure after all.
The problem seems to be that this sensor for some reason, has a high possibility of writing adjacent eeprom memory locations by mistake. Generally the behavior of the eeprom memory when trying to erase it or write it, is far from identical (reading is not problematic).
In this particular case when i tried to write memory location EE_MEAS_1 ( 0x24E1 ), memory location EE_MEAS_2 (0x24E2) was written too with the same value and vice versa. That led to wrong configuration because these two memory locations are not supposed to hold the same value, according to the datasheet.
The solution that seemed to work for me, was to erase/write something to the memory and then check if the correct values have been written. When checking the values, check all the values you want to overwrite, because one memory location may be written ok, but when you try to erase/write the next one, the former might get corrupted. So, check all the values you need to write at once (in my case the addresses 0x24E1 and 0x24E2). If the values are not correct, I reset the sensor with the appropriate command, wait for 100ms and repeat the same operation (erase/write) until the correct values are written. It usually takes two tries when i implement it with a do-while loop.
It's also good to try and write every memory location (16-bit wide) with a separate i2c command, instead of using incremental writing (as I did in the code i posted). Reading with an incremental i2c command, also does not work properly sometimes, it's best to read each address with a separate command.
I know it's not the optimal solution, but it works fairly well with no problems so far. I hope Melexis(the company that makes the sensor) will fix this issue, because from what I read others deal with the same issue too.
Best Answer
I have done I2C Communications for the Atmega32 and I interfaced a temperature sensor. Looking at the datasheet ATtiny and atmega has the same registers for I2C Communications. So you can use the following code I made for I2C Communication
This function will write the data to the I2C bus:
This function will start the I2C Communication:
This function will stop the communication:
This function will initiate the I2C bus:
Now you can use these functions in you main
NOTE: Make the last bit of your address to 0 for
writing
and 1reading
from the i2c bus