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

eeprom functions from ccs

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







eeprom functions from ccs
PostPosted: Wed Feb 04, 2004 9:07 am     Reply with quote

I try to use external eeprom 24lc65 with pic16f877 and functions from compiler doesn't work. Someone have functions to do that?

sorry for my bad english Embarassed
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Feb 04, 2004 11:56 am     Reply with quote

Look at the schematic shown in this post.
http://www.ccsinfo.com/forum/viewtopic.php?t=17787&
Do you have your EEPROM connected in the same way ?

If it still doesn't work after you check those connections,
then try this older CCS driver for the 2465.c, which they
shipped with vs. 2.7xx of the compiler. It's less complex.
It doesn't do ACK polling. It uses delays, instead.

Code:

///////////////////////////////////////////////////////////////////////////
////   Library for a MicroChip 24C65                                   ////
////                                                                   ////
////   init_ext_eeprom();    Call before the other functions are used  ////
////                                                                   ////
////   write_ext_eeprom(a, d);  Write the byte d to the address a      ////
////                                                                   ////
////   d = read_ext_eeprom(a);   Read the byte d from the address a    ////
////                                                                   ////
////   The main program may define eeprom_sda                          ////
////   and eeprom_scl to override the defaults below.                  ////
////                                                                   ////
///////////////////////////////////////////////////////////////////////////
////        (C) Copyright 1996,1997 Custom Computer Services            ////
//// This source code may only be used by licensed users of the CCS C   ////
//// compiler.  This source code may only be distributed to other       ////
//// licensed users of the CCS C compiler.  No other use, reproduction  ////
//// or distribution is permitted without written permission.           ////
//// Derivative programs created using this software in object code     ////
//// form are not restricted in any way.                                ////
////////////////////////////////////////////////////////////////////////////

#ifndef EEPROM_SDA

#define EEPROM_SDA  PIN_B7
#define EEPROM_SCL  PIN_B6

#endif

#define hi(x)  (*(&x+1))

#use i2c(master,sda=EEPROM_SDA, scl=EEPROM_SCL)

#define EEPROM_ADDRESS long int
#define EEPROM_SIZE    8192

void init_ext_eeprom() {
   output_float(eeprom_scl);
   output_float(eeprom_sda);
}


void write_ext_eeprom(long int address, byte data) {

   i2c_start();
   i2c_write(0xa0);
   i2c_write(hi(address));
   i2c_write(address);
   i2c_write(data);
   i2c_stop();
   delay_ms(11);
}


byte read_ext_eeprom(long int address) {
   byte data;

   i2c_start();
   i2c_write(0xa0);
   i2c_write(hi(address));
   i2c_write(address);
   i2c_start();
   i2c_write(0xa1);
   data=i2c_read(0);
   i2c_stop();
   return(data);
}
Marcus
Guest







PostPosted: Fri Feb 06, 2004 12:03 pm     Reply with quote

I've tried your functions and the functions of the ccs compilator and anyone seems to be correct. I use the 24lc65 and i tried to put your function for my eeprom. Maybe it doesnt function.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Feb 06, 2004 12:13 pm     Reply with quote

Quote:
I've tried your functions and the functions of the ccs compilator and anyone seems to be correct. I use the 24lc65 and i tried to put your function for my eeprom. Maybe it doesn't function.


Did you wire your EEPROM circuit according to the schematic link,
that I gave in my previous post ? (including the pull-up resistors ?)

The 24LC65 has an unusual feature. It has a one-time programmable
security option, which write-protects blocks of memory inside the chip.
These security fuses are very, very easy to set. There is no special
sequence of bytes or special registers that you have to write to, in order
to enable this option. I think you could easily set the security fuse
by accident. Then the chip will appear to be "defective".

My suggestion is to start with a more simple EEPROM chip. Use a
24LC256 instead. CCS has drivers for this. I have posted test
programs on this board in the past, for this chip. You should use it
as your first chip.
Marcus
Guest







PostPosted: Fri Feb 06, 2004 12:51 pm     Reply with quote

My circuit is the same as yours(with pull-up). I can't use 24lc256 because i only have 24lc65 in my possession. What are the fuse you talk about? Why i can disable it?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Feb 06, 2004 1:22 pm     Reply with quote

Quote:
What are the fuse you talk about?


Some excerpts from the 24LC65 data sheet:
Quote:
The 24LC65 has a sophisticated mechanism for
write-protecting portions of the array. This write protect
function is programmable and allows the user to protect
0-15 contiguous 4K blocks.

The user sets the security option by sending to the device
the starting block number for the protected region and the
number of blocks to be protected.

THE SECURITY OPTION CAN BE SET ONLY ONCE.

To invoke the security option, a write command is sent
to the device with the leading bit (bit 7) of the first
address byte set to a 1 (Figure 8-1). Bits 1-4 of the first
address byte define the starting block number for the
protected region. For example, if the starting block
number is to be set to 5, the first address byte would be
1XX0101X. write command.


If you have accidently done this, your EEPROM is now
permanently write-protected. Or, if the chips were given
to you by someone who previously did this operation, the
chips can't be used anymore. You can't write to them.

This is why, as a newbie, you should not be using these chips.
You can't know for sure, if the problem is in your circuit, or
the PIC program, or if the 24LC65 chips are write-protected.
They are not good chips to learn with.
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