View previous topic :: View next topic |
Author |
Message |
tienchuan
Joined: 25 Aug 2009 Posts: 175
|
Can't write and read eeprom with address larger 512 |
Posted: Wed Jul 31, 2013 7:01 am |
|
|
Hi all.
I'm have a problem when try to write and read again with address large 512
( i'm using Serial EEPROM AT24C04A 4KB, interface I2C of ATMEL). The results output terminal are failed.
In my project i'm using driver for this EEPROM (2404.c) to control it, and
PIC18F4680
CCS C ver 4.140, and there is code:
Code: |
for(i=0;i<=20;i++)
{
write_ext_eeprom(i+512,'K');
}
delay_ms(100);
for(i=0;i<=20;i++)
{
putc(read_ext_eeprom(i+512));
}
delay_ms(100);
|
In this driver ( 2404.c) of CCS C, I find this define
Code: | #define EEPROM_SIZE 512 |
but it never used for this driver?
Pls show me way to solve this problem?
Thanks. _________________ Begin Begin Begin !!! |
|
![](templates/subSilver/images/spacer.gif) |
drh
Joined: 12 Jul 2004 Posts: 192 Location: Hemet, California USA
|
|
Posted: Wed Jul 31, 2013 8:27 am |
|
|
That should be 4Kb (bits), not 4KB (bytes). That part will hold 512 bytes. Read the data sheet. _________________ David |
|
![](templates/subSilver/images/spacer.gif) |
dyeatman
Joined: 06 Sep 2003 Posts: 1924 Location: Norman, OK
|
|
Posted: Wed Jul 31, 2013 9:33 am |
|
|
First sentence in the datasheet:
Quote: | The AT24C02A/04A provides 2048/4096 bits of serial electrically
erasable and programmable read-only memory (EEPROM)
organized as 256/512 words of 8 bits each |
_________________ Google and Forum Search are some of your best tools!!!! |
|
![](templates/subSilver/images/spacer.gif) |
tienchuan
Joined: 25 Aug 2009 Posts: 175
|
|
Posted: Tue Aug 06, 2013 8:39 pm |
|
|
In driver for this EEPROM ( AT24C04) of CCS C (ver 4.140)
Code: |
void write_ext_eeprom(long int address, BYTE data) {
while(!ext_eeprom_ready());
i2c_start();
i2c_write((0xa0|(BYTE)(address>>7))&0xfe);
i2c_write(address);
i2c_write(data);
i2c_stop();
}
|
I don't known why
Code: | i2c_write((0xa0|(BYTE)(address>>7))&0xfe); |
pls show me it?
thanks _________________ Begin Begin Begin !!! |
|
![](templates/subSilver/images/spacer.gif) |
oxo
Joined: 13 Nov 2012 Posts: 219 Location: France
|
|
Posted: Wed Aug 07, 2013 1:11 am |
|
|
tienchuan wrote: |
Code: | i2c_write((0xa0|(BYTE)(address>>7))&0xfe); |
pls show me it?
thanks |
It's the device address and the R/W bit. Figure 10 in the datasheet |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19369
|
|
Posted: Wed Aug 07, 2013 2:14 am |
|
|
On the 'EEPROM_SIZE' define, this is available for _you_ to use. All the EEPROM drivers #define this, so that you can write your code to be 'generic', and for instance loop through the whole EEPROM, with:
for (count=0;count<EEPROM_SIZE, count++)
etc..
For whichever EEPROM you have selected.
It is just like the 'limits'h' defines, for maths, where there are the sizes of each type of variable etc., defined.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
|