PDA

View Full Version : Help with i2C eeprom



Squibcakes
- 16th March 2006, 01:18
Gidday,

I got some 24LC256 Eeprom samples the other day and I've been trying to learn the in's and out's of I2C programming!

I've come unstuck. Not sure that the problem is with my configuration or what???

Can some one have a quicky look at my code and put me in the right direction.. taa.

Code explanation is pretty straight fwd taken from pic compiler sample codes...

Thanks
J

mister_e
- 16th March 2006, 03:27
Control Byte must be 8 bits... not 9...and you don't have to modify it. I2CREAD/I2CWRITE will handle it for you.

One other thing, not sure of me for that one, I don't know if...
I2CREAD plahplahplah...[MyVar]
wich MyVar is pre-define as a word sized variable is a valide statement. BUT
I2CREAD plahplahplah...[MyVar.LowByte,MyVar.HighByte]
Is a valid statement.

NOW...

DEFINE I2C_SLOW 1 'Use for >8MHz OSC with standard speed devices
DEFINE I2C_SDA PORTB,1 'Data pin for I2C (12-bit core only)
DEFINE I2C_SCL PORTB,4 'Clock pin for I2C (12-bit core only)
SSPSTAT.7=0
SSPSTAT.6=0
SSPCON.5=1
SSPCON.4=1
SSPCON.3=1
SSPCON.2=0
SSPCON.1=1
SSPCON.0=1

Duh???

Squibcakes
- 17th March 2006, 00:13
Thanks Steve,

Got it!

Yeah I was trying to follow the F88 data sheet, eeprom data sheet, and Picpro manual and got all muddled up!

It's suprising that I2CREAD/I2CWRITE handles the control byte, I really thought that I had to manually modify it.

Looks like I2CREAD/I2CWRITE handles the register stuff too. :--)

Okay, well I've attached an updated code listing for anyone interested in programming a I2C EEPROM chip.

(I'm only doing this because this forum keeps putting a banner at the top of the page telling me to Post something!!!)


Cheers
Jared

mister_e
- 17th March 2006, 00:16
I2CREAD/I2CWRITE ae software solution and don't use the internal MSSP module. Easier but slower.. no big deal depending the application

Squibcakes
- 17th March 2006, 00:28
Steve,

You wouldn't be able to give us a few examples of the "other" faster method that uses the MSSP module.

I think this is what I was trying to do in the first place when I became unstuck.

Cheers
J

mister_e
- 17th March 2006, 00:33
I could.. but those MSSP routines (i2C master/Slave, SPI master/Slave) took me awhile to figure and become stable, mature, plahplahplah... There's some nifty code example on the Melabs website.

Do you really need higher speed btw?