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 support@ccsinfo.com

Basics of EEPROM - Can someone help?

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







Basics of EEPROM - Can someone help?
PostPosted: Tue Jan 27, 2004 9:31 pm     Reply with quote

I'm trying to learn to use the eeprom as shown in the CCS Exercise book.

The code does not have any comment so I wonder if anyone can try to make sense out of it as I'm new to eeprom.

I don't know the basics of it, how it's addressed, how it's initialised, and so on.

I have included the code so maybe, someone can put comments for me so I can understand it. I know the C language, so I only need an understanding of the eeprom. I'd like to start with a simple eeprom, like the one in the example.

#ifndef EEPROM_SELECT

#define EEPROM_SELECT PIN_B4
#define EEPROM_CLK PIN_B2
#define EEPROM_DI PIN_B1
#define EEPROM_DO PIN_B0

#endif

#define EEPROM_ADDRESS BYTE
#define EEPROM_SIZE 256

void init_ext_eeprom() {
BYTE cmd[2];
BYTE i;

output_low(EEPROM_DI);
output_low(EEPROM_CLK);
output_low(EEPROM_SELECT);

cmd[0]=0x80;
cmd[1]=0x9;

for(i=1;i<=4;++i)
shift_left(cmd,2,0);
output_high(EEPROM_SELECT);
for(i=1;i<=12;++i) {
output_bit(EEPROM_DI, shift_left(cmd,2,0));
output_high(EEPROM_CLK);
output_low(EEPROM_CLK);
}
output_low(EEPROM_DI);
output_low(EEPROM_SELECT);
}


void write_ext_eeprom(EEPROM_ADDRESS address, BYTE data) {
BYTE cmd[3];
BYTE i;

cmd[0]=data;
cmd[1]=address;
cmd[2]=0xa;

for(i=1;i<=4;++i)
shift_left(cmd,3,0);
output_high(EEPROM_SELECT);
for(i=1;i<=20;++i) {
output_bit(EEPROM_DI, shift_left(cmd,3,0));
output_high(EEPROM_CLK);
output_low(EEPROM_CLK);

}
output_low(EEPROM_DI);
output_low(EEPROM_SELECT);
delay_ms(11);
}


BYTE read_ext_eeprom(EEPROM_ADDRESS address) {
BYTE cmd[3];
BYTE i,data;

cmd[0]=0;
cmd[1]=address;
cmd[2]=0xc;

for(i=1;i<=4;++i)
shift_left(cmd,3,0);
output_high(EEPROM_SELECT);
for(i=1;i<=20;++i) {
output_bit(EEPROM_DI, shift_left(cmd,3,0));
output_high(EEPROM_CLK);
output_low(EEPROM_CLK);

if(i>12)
shift_left(&data,1,input(EEPROM_DO));
}
output_low(EEPROM_SELECT);
return(data);
}
Guest_X44
Guest







PostPosted: Tue Jan 27, 2004 9:52 pm     Reply with quote

By the way, the eeprom is 93LC56A.
Ttelmah
Guest







PostPosted: Wed Jan 28, 2004 3:29 am     Reply with quote

Guest_X44 wrote:
By the way, the eeprom is 93LC56A.

Before looking any further, critical comment. You have (hopefully) got the pull-up resistors on the two signalling lines?. These are _essential_.

Best Wishes
neil



Joined: 08 Sep 2003
Posts: 128

View user's profile Send private message

?
PostPosted: Wed Jan 28, 2004 4:02 am     Reply with quote

Isn't the 93x series of EEPROMS an SPI/microwire interface? These won't need pullups surely? This is a 3 wire bus.
Ttelmah
Guest







Re: ?
PostPosted: Wed Jan 28, 2004 10:45 am     Reply with quote

neil wrote:
Isn't the 93x series of EEPROMS an SPI/microwire interface? These won't need pullups surely? This is a 3 wire bus.

In which case ignore this comment. However I thought the example given in the CCS book, was for an I2C device not SPI (which could explain a lot...).

Best Wishes
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

Re: Basics of EEPROM - Can someone help?
PostPosted: Wed Jan 28, 2004 11:48 am     Reply with quote

Guest_X44 wrote:
I'm trying to learn to use the eeprom as shown in the CCS Exercise book.

The code does not have any comment so I wonder if anyone can try to make sense out of it as I'm new to eeprom.

I don't know the basics of it, how it's addressed, how it's initialised, and so on.

I have included the code so maybe, someone can put comments for me so I can understand it. I know the C language, so I only need an understanding of the eeprom. I'd like to start with a simple eeprom, like the one in the example.

#ifndef EEPROM_SELECT

#define EEPROM_SELECT PIN_B4
#define EEPROM_CLK PIN_B2
#define EEPROM_DI PIN_B1
#define EEPROM_DO PIN_B0

#endif

#define EEPROM_ADDRESS BYTE
#define EEPROM_SIZE 256

void init_ext_eeprom() {
BYTE cmd[2];
BYTE i;

output_low(EEPROM_DI);
output_low(EEPROM_CLK);
output_low(EEPROM_SELECT);

cmd[0]=0x80;
cmd[1]=0x9;

for(i=1;i<=4;++i)
shift_left(cmd,2,0);
output_high(EEPROM_SELECT);
for(i=1;i<=12;++i) {
output_bit(EEPROM_DI, shift_left(cmd,2,0));
output_high(EEPROM_CLK);
output_low(EEPROM_CLK);
}
output_low(EEPROM_DI);
output_low(EEPROM_SELECT);
}


void write_ext_eeprom(EEPROM_ADDRESS address, BYTE data) {
BYTE cmd[3];
BYTE i;

cmd[0]=data;
cmd[1]=address;
cmd[2]=0xa;

for(i=1;i<=4;++i)
shift_left(cmd,3,0);
output_high(EEPROM_SELECT);
for(i=1;i<=20;++i) {
output_bit(EEPROM_DI, shift_left(cmd,3,0));
output_high(EEPROM_CLK);
output_low(EEPROM_CLK);

}
output_low(EEPROM_DI);
output_low(EEPROM_SELECT);
delay_ms(11);
}


BYTE read_ext_eeprom(EEPROM_ADDRESS address) {
BYTE cmd[3];
BYTE i,data;

cmd[0]=0;
cmd[1]=address;
cmd[2]=0xc;

for(i=1;i<=4;++i)
shift_left(cmd,3,0);
output_high(EEPROM_SELECT);
for(i=1;i<=20;++i) {
output_bit(EEPROM_DI, shift_left(cmd,3,0));
output_high(EEPROM_CLK);
output_low(EEPROM_CLK);

if(i>12)
shift_left(&data,1,input(EEPROM_DO));
}
output_low(EEPROM_SELECT);
return(data);
}



To prepair the EEPROM to clock in comand or data:
Code:

   output_low(EEPROM_DI);
   output_low(EEPROM_CLK);
   output_low(EEPROM_SELECT);

This is the long way to put something simple.
Code:

cmd[0]=0x80;
cmd[1]=0x9;

for(i=1;i<=4;++i)
shift_left(cmd,2,0);

It should be
Code:

cmd[0]=0x00;
cmd[1]=0x98;


This will send the high bit to the EEPROM 12 times. It will also shift the value in cmd at the same time, causing the desired value to be shifted out.
Code:

for(i=1;i<=12;++i) {
output_bit(EEPROM_DI, shift_left(cmd,2,0));
output_high(EEPROM_CLK);
output_low(EEPROM_CLK);


This indicates that this transfer is complete:
Code:

output_low(EEPROM_DI);
output_low(EEPROM_SELECT);

The rest is more of the same. It would be easier to read if the shifted variables were not byte arrays. Read up on the shift command documented in the manual.
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Wed Jan 28, 2004 12:33 pm     Reply with quote

Neutone's comments are good but I would add that you should get a copy of the data sheet for the EEPROM you are trying to use.

Programming for microcontrollers means you need to learn how to read a datasheet so no time like the present... Cool
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
Guest_X44
Guest







PostPosted: Wed Jan 28, 2004 6:03 pm     Reply with quote

Thanks to everyone, specially to Neutone.

I'm still coming to grips on this.

In the init_ext_eeprom() constaing the following code:

cmd[0]=0x80;
cmd[1]=0x9;

for(i=1;i<=4;++i)
shift_left(cmd,2,0);
output_high(EEPROM_SELECT);
for(i=1;i<=12;++i)
{
output_bit(EEPROM_DI, shift_left(cmd,2,0));
output_high(EEPROM_CLK);
output_low(EEPROM_CLK);
}
output_low(EEPROM_DI);
output_low(EEPROM_SELECT);

QUESTION: In looping 12 times it will output_bit the value 0x980 (prior to left-shifting cmd[1] = 0x09 and cmd[0] = 0x80 ). What's this 0x980 value then?


***
Going through the read_ext_eeprom(EEPROM_ADDRESS address) function :

for(i=1;i<=20;++i)
{ BYTE cmd[3];
BYTE i,data;

cmd[0]=0;
cmd[1]=address;
cmd[2]=0xc;

for(i=1;i<=4;++i)
shift_left(cmd,3,0);
output_high(EEPROM_SELECT);
for(i=1;i<=20;++i) {
output_bit(EEPROM_DI, shift_left(cmd,3,0));
output_high(EEPROM_CLK);
output_low(EEPROM_CLK);

if(i>12)
shift_left(&data,1,input(EEPROM_DO));
}
output_low(EEPROM_SELECT);
return(data);
}

QUESTION: Why write this and what's it got to do with reading? And why cycle 20 times? Also, the variable data is declared but not initialised.
Guest_X44
Guest







PostPosted: Wed Jan 28, 2004 6:04 pm     Reply with quote

Thanks to everyone, specially to Neutone.

I'm still coming to grips on this.

In the init_ext_eeprom() constaing the following code:

cmd[0]=0x80;
cmd[1]=0x9;

for(i=1;i<=4;++i)
shift_left(cmd,2,0);
output_high(EEPROM_SELECT);
for(i=1;i<=12;++i)
{
output_bit(EEPROM_DI, shift_left(cmd,2,0));
output_high(EEPROM_CLK);
output_low(EEPROM_CLK);
}
output_low(EEPROM_DI);
output_low(EEPROM_SELECT);

QUESTION: In looping 12 times it will output_bit the value 0x980 (prior to left-shifting cmd[1] = 0x09 and cmd[0] = 0x80 ). What's this 0x980 value then?


***
Going through the read_ext_eeprom(EEPROM_ADDRESS address) function :

for(i=1;i<=20;++i)
{ BYTE cmd[3];
BYTE i,data;

cmd[0]=0;
cmd[1]=address;
cmd[2]=0xc;

for(i=1;i<=4;++i)
shift_left(cmd,3,0);
output_high(EEPROM_SELECT);
for(i=1;i<=20;++i) {
output_bit(EEPROM_DI, shift_left(cmd,3,0));
output_high(EEPROM_CLK);
output_low(EEPROM_CLK);

if(i>12)
shift_left(&data,1,input(EEPROM_DO));
}
output_low(EEPROM_SELECT);
return(data);
}

QUESTION: Why write this and what's it got to do with reading? And why cycle 20 times? Also, the variable data is declared but not initialised.
Guest_X44
Guest







PostPosted: Wed Jan 28, 2004 7:49 pm     Reply with quote

Now I get it. I know why it's looped. I studied the timing diagram of both the Read and Write Cycles.

But what is still not clear to me is during the initialisation. It's looped 12 times and its basically sending 12 bits. The first 3 bits are 1, 0, 0.
The second and third bits represent the opcode. I'm still confused because this is the opcode for either ERASE ALL or ERASE/WRITE ENABLE.

So, what could it be? And what should it be?
Guest_X44
Guest







PostPosted: Thu Jan 29, 2004 4:04 am     Reply with quote

Is it necessary to put a delay after a write as shown in the CCS Exercise?
As you can see, the write function has a delay_ms(11), but the read function does not have any delay at all.

If it's necessary to put a delay, then what is the minimum required?
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