View previous topic :: View next topic |
Author |
Message |
Greg- Guest
|
Problem with PIC16f877 and 24lc256 |
Posted: Wed Dec 24, 2003 6:15 pm |
|
|
Hi,
I have connected my pic16f877 to a 24lc256 eeprom memory chip, i have used port e 0 and 1 for the SCL and SDA lines. I have compiled and loaded the EX_EXTEE.C example from the examples directory. when i attempt to read from the eeprom chip it always returns "FF" even though the value at the address is not "FF", as i preloaded soem data onto it using my pic/eeprom programmer, does anyone have any ideas to what may be going wrong?
Also at 20mhz and 5 volts what values should i be using for the two pull up resistors, and just to check, what format should the address be entered for the EX_EXTEE.C file when it asks for the memory address to read/write from.
Thanks in advance,
Greg |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Dec 24, 2003 7:17 pm |
|
|
Quote: | At 20mhz and 5 volts what values should i be using for the two pull up resistors ? |
This thread has a schematic which shows the resistor size
and the connections to the PIC.
http://www.ccsinfo.com/forum/viewtopic.php?t=17787
----------------------------
Quote: | What format should the address be entered for the EX_EXTEE.C file
when it asks for the memory address to read/write from ? |
From looking at the file, it looks like you should do this to read a byte:
(Answers shown in bold)
Read or Write: R
Location: 0000
------------------------------
This assumes that you edited the EX_EXTEE.C file, to include the
proper driver file for the 24LC256. ie., the example file has this:
But you should change it to this:
---------------------------------------
And of course, if your programmer didn't really program the bytes
to some other value than 0xFF, then the EX_EXTEE.C program will
still read 0xFF. If it still doesn't work after doing all the changes
given above, then use the Write command of EX_EXTEE.C to write
a value such as 0x55 to address 0000, and then use the 'R' command
to read it back. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Wed Dec 24, 2003 7:31 pm |
|
|
Silly question, but did you change the following lines
Code: |
#define EEPROM_SDA PIN_B1
#define EEPROM_SCL PIN_B0
|
to
Code: |
#define EEPROM_SDA PIN_E1
#define EEPROM_SCL PIN_E0
|
|
|
|
Greg- Guest
|
|
Posted: Wed Dec 24, 2003 7:52 pm |
|
|
Thanks for the replies!
Well yes, i changed the definitions to use E0 and E1 and also i tried the write command, and also i eddited the 2416.c file to say this:
Code: | #define EEPROM_SIZE 32768 |
instead of:
Code: | #define EEPROM_SIZE 2048 |
as i didnt seem to get the 24256.c in the driver directory. is that sufficient?
i used my programmer to read the data from the eeprom, and it shows up as having the data i have written to it previously(using the programmer), but it seems that the byte i try to write using the write command from EX_EXTEE.C doesnt seem to actually get written. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Wed Dec 24, 2003 8:08 pm |
|
|
Nope, the addressing is different for the 24lc256
24c16:
Code: |
i2c_write((0xa0|(byte)(address>>7))&0xfe);
i2c_write(address);
|
24lc256:
Code: |
i2c_write(0xa0);
i2c_write(address>>8);
i2c_write(address);
|
Code: |
void write_ext_eeprom(long address, int data)
{
i2c_start();
i2c_write(0xA0);
i2c_write(address>>8);
i2c_write(address);
i2c_write(data);
i2c_stop();
i2c_start();
// until the write is complete
while(i2c_write(0xA0))
{
i2c_start();
}
}
byte read_ext_eeprom(long address)
{
int data;
i2c_start();
i2c_write(0xA0);
i2c_write(address>>8);
i2c_write(address);
i2c_start();
i2c_write(0xA1);
data=i2c_read(0);
i2c_stop();
return(data);
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Dec 24, 2003 8:40 pm |
|
|
Quote: | I didn't seem to get the 24256.c in the driver directory |
You should have told us that up front.
It's available here:
http://www.cc.puv.fi/~t0101190/projekti/source/original/Drivers/
Though, in the version that's posted on that page, there is one error.
It has an incorrect eeprom size:
#define EEPROM_SIZE 16384
You should change it to this:
#define EEPROM_SIZE 32768 |
|
|
|