CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Can't write and read eeprom with address larger 512

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
tienchuan



Joined: 25 Aug 2009
Posts: 175

View user's profile Send private message Yahoo Messenger

Can't write and read eeprom with address larger 512
PostPosted: Wed Jul 31, 2013 7:01 am     Reply with quote

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 !!!
drh



Joined: 12 Jul 2004
Posts: 192
Location: Hemet, California USA

View user's profile Send private message

PostPosted: Wed Jul 31, 2013 8:27 am     Reply with quote

That should be 4Kb (bits), not 4KB (bytes). That part will hold 512 bytes. Read the data sheet.
_________________
David
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

PostPosted: Wed Jul 31, 2013 9:33 am     Reply with quote

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!!!!
tienchuan



Joined: 25 Aug 2009
Posts: 175

View user's profile Send private message Yahoo Messenger

PostPosted: Tue Aug 06, 2013 8:39 pm     Reply with quote

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 !!!
oxo



Joined: 13 Nov 2012
Posts: 219
Location: France

View user's profile Send private message

PostPosted: Wed Aug 07, 2013 1:11 am     Reply with quote

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
Ttelmah



Joined: 11 Mar 2010
Posts: 19518

View user's profile Send private message

PostPosted: Wed Aug 07, 2013 2:14 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group