Page 1 of 1

I2C / EEPROM Problem

Posted: 01 Oct 2010 12:49
by gas
I've started trying to get an EEPROM on a I2C-line working.

The development board I use is an LV 24-33A with PIC24FJ96GA010 MCU.

I have a program where I utilize the touch screen with pretty much the same code as the touch panel example. I want to try and save the calibration data to EEPROM, but apparently it doesn't work all that well.

The code I'm using for writing / reading to/from eeprom is as follows:

Code: Select all

EEPROM_WrSingle(0x02,cal_x_min);
EEPROM_WrSingle(0x03,cal_y_min);
EEPROM_WrSingle(0x04,cal_x_max);
EEPROM_WrSingle(0x05,cal_y_max);

Code: Select all

cal_x_min=Eeprom_RdSingle(0x02);
cal_y_min=Eeprom_RdSingle(0x03);
cal_x_max=Eeprom_RdSingle(0x04);
cal_y_max=Eeprom_RdSingle(0x05);
As soon as I run that code, my touch panel won't response at all (probably because the calibration values somehow have become corrupt). Which is kinda weird, because in it's essence, that code snippet shouldn't change the calibration values at all.

Anyone know what could be wrong?

I've modified the Eeprom library slightly (changed I2C_Start to I2C1_start etc.) to match my setup.

Re: I2C / EEPROM Problem

Posted: 01 Oct 2010 13:06
by gas
I'm starting to think, could it be that the calibration values are larger than one byte? If so, could anyone hint as to how I would split them up into several 8-bit values?

Re: I2C / EEPROM Problem

Posted: 02 Oct 2010 09:10
by Sobrietytest
Check out the Lo, Hi, Higher and Highest operators, using these you will be able to deconstruct values between 2 and 4 bytes in length and save them as single byte chunks in your EEPROM. Remember to use the bitshift operators (<<) when you reconstruct the values after reading from memory.

Re: I2C / EEPROM Problem

Posted: 03 Oct 2010 10:09
by pwdixon
I take it that in your tests there was a time delay between writing and reading EEPROM values as trying to read directly after a write does cause problems. Leave something like more than 20ms before reading after a write.

Re: I2C / EEPROM Problem

Posted: 07 Nov 2010 15:27
by netos
- do you have pull-up resistors properly installed on I2C line?
- your mcu is a 3.3V device. confirm your i2c memory on its datasheet that can operate on 3.3v
- most of eeproms operate slower whet its powered by 3.3v source. add delays between writing single bytes
- check eeprom's datasheet about page-writing so you can save all your data faster