I2C / EEPROM Problem

General discussion on mikroC.
Post Reply
Author
Message
gas
Posts: 18
Joined: 17 Aug 2010 06:12
Location: Denmark
Contact:

I2C / EEPROM Problem

#1 Post by gas » 01 Oct 2010 12:49

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.
- Tommy S.
Industrial Automation

gas
Posts: 18
Joined: 17 Aug 2010 06:12
Location: Denmark
Contact:

Re: I2C / EEPROM Problem

#2 Post by gas » 01 Oct 2010 13:06

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?
- Tommy S.
Industrial Automation

Sobrietytest
Posts: 619
Joined: 05 Jul 2008 06:05
Location: Thailand

Re: I2C / EEPROM Problem

#3 Post by Sobrietytest » 02 Oct 2010 09:10

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.

pwdixon
Posts: 1431
Joined: 13 Apr 2005 11:14
Location: UK

Re: I2C / EEPROM Problem

#4 Post by pwdixon » 03 Oct 2010 10:09

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.

netos
Posts: 36
Joined: 15 Aug 2008 01:03

Re: I2C / EEPROM Problem

#5 Post by netos » 07 Nov 2010 15:27

- 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

Post Reply

Return to “mikroC General”