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

24LC128 addressing

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



Joined: 14 Jun 2005
Posts: 64

View user's profile Send private message

24LC128 addressing
PostPosted: Sat Feb 25, 2006 8:06 am     Reply with quote

Hi- a couple of questions about this eeprom and the i2c protocol:
I don't understand the data sheet for the 24LC128.
http://ww1.microchip.com/downloads/en/devicedoc/21191m.pdf
In the device addressing section, there is a diagram of control bits and how to address multiple eeproms. I think this means if I want to address an chip with pins 1,2,3 wired as +5, gnd,gnd, I should put A2 in my code. Because bit 0 is the R/W bit.
Of course, if this worked I wouldn't be asking. Here's a code snip. Credit for all the comments comes from this forum so if you see something wrong please tell me...

Code:
#include <16f877.H>
#use delay(clock=20000000)
#use i2c(Master, SDA=PIN_C4, SCL=PIN_C3)
#fuses hs,noprotect,nowdt,put
#byte PORTB=6
#include <24128.c>
#include <LCD_16f877A.c>
#use fast_io(b)

main()
{
int data;
long int a=0;
int i;
set_tris_a(0b00100000);      // sets Port a direction 0=out 1=in
set_tris_b(0);               // sets Port b all outputs
portb=0x00;                  // init Port b sets all pins low
delay_ms(1000);              // delay for settling
lcd_init();                  // init LCD
init_ext_eeprom();           // init 24128, call before the other functions are used
portb = data;                // variable data = port B
printf(lcd_putc,"\nnew2");
delay_ms(1000);
i2c_start();
i2c_write(0xA0);              //address of eeprom #1
i2c_write(0x00);              // do 2x for timing
i2c_write(0x00);
i2c_start();
i2c_write(0xA1);              //Sequential read forever
printf(lcd_putc,"\nBegin Read           ");
do
{
data = i2c_read();
portb = data;
delay_us(15);
}while(1);
i2c_stop();
printf(lcd_putc,"\nComplete!       ");
}


Also- is it possible to place my file in a specific address? Right now, I program the chip using PonyProg.

Next question: I only knew the order of the i2c code because of what I saw others here do. Where would I have found this information?

Thanks in advance-
SophE
Ttelmah
Guest







PostPosted: Sat Feb 25, 2006 9:22 am     Reply with quote

Yes. The addressing is right.
The comment 'do x2 for timing', is silly. You write two bytes, because the byte address in the ROM, requires 14bits. Nothing to do with 'timing'.
How do you exit the read?...
It is going to read for ever. You need to count the bytes, and stop.
If it ever left the loop, the printf, assuming it is using the hardware port, would not complete, since the code will overrun into the hidden 'sleep' instruction, and would not send the last three bytes.
Why load 24128.c. You are not using it.
What 'file'. If you mean the C code, for the processor, look at #build. However be aware, that the reset, and interrupt vectors Must_ be at their default locations, unless you have redirection code present.

The data sheet.

Best Wishes
Sophi



Joined: 14 Jun 2005
Posts: 64

View user's profile Send private message

PostPosted: Sat Feb 25, 2006 9:59 am     Reply with quote

Thanks Ttelmah-
Yes I mean for it to loop forever. Its a test sound file. By file I mean the binary file that I am loading into the 24LC128, I only need to read from the eeprom so I load my file in it with software PP. PonyProg stores it starting at
0. I would like to store more than one file where I choose to store them.

Don't I need 24128 to use init_ext_eeprom()?

I don't get that from the data sheet- whereabouts?

SophE
Ttelmah
Guest







PostPosted: Sat Feb 25, 2006 3:31 pm     Reply with quote

Yes, you do need 24128, to use the init call. However the initialisation sequence, is not actually needed. Just float the two lines, and wait for long enough for the chip to fully wake up.

Best Wishes
jds-pic



Joined: 17 Sep 2003
Posts: 205

View user's profile Send private message

Re: 24LC128 addressing
PostPosted: Mon Feb 27, 2006 10:19 am     Reply with quote

Sophi wrote:
Hi- a couple of questions about this eeprom and the i2c protocol:
I don't understand the data sheet for the 24LC128.
http://ww1.microchip.com/downloads/en/devicedoc/21191m.pdf
In the device addressing section, there is a diagram of control bits and how to address multiple eeproms. I think this means if I want to address an chip with pins 1,2,3 wired as +5, gnd,gnd, I should put A2 in my code. Because bit 0 is the R/W bit.


see also the EEPROM code here:
http://www.ccsinfo.com/forum/viewtopic.php?t=19526

jds-pic
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