Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

I2C communication EEPROM/PIC

Status
Not open for further replies.

Spow

Newbie level 3
Joined
Apr 13, 2010
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,306
Hi,

I'm trying to have an EEPROM and a PIC successfully communicate through the I²C bus.
The accelerometer worked out just fine in I²C (on the same circuit), but I don't seem to be able to read/write data on the EEPROM.
I saw a lot of code on the internet, and mine is pretty standard for that matter (though i coded it myself)

Code:
i2c_start();
i2c_write(0xA0); // SLAVE adress 0 (write)
i2c_write(0x00); // register from l'EEPROM
i2c_write(0x01); // second part of the register adress from the EEPROM (it's a big one :p)
i2c_write(0xAA);
i2c_stop();

i2c_start();
i2c_write(0xA1); // read mode
i2c_write(0x00);
i2c_write(0x01);
i2c_start();
i2c_write(0xA1);
if(i2c_read(0) == 0xAA) output_bit(PIN_C2, 1); //lit a DEL
i2c_stop();


But DEL C2 never lits ! The program does not crash/block though, it simply reads 'FF' when i copy what i read in external eeprom to the internal EEPROM (and visualise it in MPlab).
Is my code wrong ? Or does it come from the hardware ? ( I placed pull-ups on the I²C, though i'm unsure it works)

Thaks for having read.
 

Is the slave device (the eeprom) acknowledging? May want an o-scope to determine this.
 

I don't have access to such materials :S

I placed a code portion supposed to lit a DEL if i2c_write() returns 1, and it works.
 

Is one in your code success or failure?

besides oscilloscope, you may try to check in the software if it is returning bit error and what are the values of in I2CS register.
 

Can you run a debugger? You may be able to determine if the eeprom is acknowledging via the debugger.
 

If you are using the Hi-Tech compiler use the routines that are in the samples folder.
You just need to edit 'i2c.h' to suit your setup.
'i2c.h' contains the following function prototypes.

Code:
extern signed char    i2c_ReadAcknowledge(void);
extern unsigned char  i2c_SendAddress(unsigned char, unsigned char);
extern unsigned char  i2c_SendByte(unsigned char);
extern int            i2c_ReadByte(void);
extern void           i2c_Restart(void);
extern void           i2c_Stop(void);
extern void           i2c_SendAcknowledge(unsigned char);
extern signed char    i2c_PutByte(unsigned char);
extern int            i2c_GetByte(unsigned char);
extern unsigned char  i2c_Open(unsigned char, unsigned char);
extern unsigned char  i2c_GetString(unsigned char *, unsigned char);
extern int            i2c_PutString(const unsigned char *, unsigned char);
extern unsigned char  i2c_WaitForSCL(void);
extern void           i2c_Free(void);
extern unsigned char  i2c_read(unsigned char);
 

I found the answer ^^

This portion of code actually was in a for() instruction, and as there were no delays included, it failed most of the time. I must have modified something else though, for I am pretty sure that none of the requests above ever succeeded before. I noticed the delay thing when 4 out of 5 requests failed, but I don't happen to know what triggered one to eventually work.

I'm now mixing both the codes from the accelerometer and the EEPROM and will hopefully be done soon :p

Thanks for your help
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top