View previous topic :: View next topic |
Author |
Message |
Sophi
Joined: 14 Jun 2005 Posts: 64
|
24LC256 Read from specific address |
Posted: Sun Apr 09, 2006 7:18 am |
|
|
Hi- I am trying to read from a specific address inside an i2C 24LC256 eeprom.
1. My code works fine if I start at internal address '0000' altho I think I might just be lucky and am missing some basic concept here.
Addressing each eeprom A1, A2, A3 etc. seems to work also.
2. In addition, I don't understand from the data sheet if I am supposed to generate an "ACK" or if it is done automatically (I'm working in CCS C).
3. using i2c_write(0x23E0) to access memory location ...occasionally my read starts from somewhere else in the memory but it is totally unreliable
4. I use a for loop to control how many bytes to read. Is this correct?
Thanks for any help in advance.
SophE
link to data sheet is http://ww1.microchip.com/downloads/en/DeviceDoc/21203N.pdf
Code: | #include <16F877A.H>
#fuses HS,NOWDT,NOPROTECT, PUT, BROWNOUT, NOLVP
#use delay(clock=20000000)
#use i2c(Master, SDA=PIN_C4, SCL=PIN_C3)
#include <LCD_16f877A.c>
#use fast_io(a)
#use fast_io(b)
#include <stdlib.h>
#BYTE PORTB=6
//*****************************************************************
void main()
{
int data;
set_tris_a(0b11110011); // sets port a direction 0=out 1=in
set_tris_b(0x00); //
init:
lcd_init(); // for LCD driver
portb=0x00; // init Port b sets all pins low
lcd_putc("\feeprom4 ");
delay_ms(1000);
output_float(PIN_C3); // init 24256 eeprom
output_float(PIN_C4);
delay_ms(1000);
i2c_start();
i2c_write(0b10100010); // control read/write/eeprom address 001/write 0
i2c_write(0x23E0); // internal address to start -MSB first, then LSB
// 14 bit address, 2 MSB XX
int32 j;
i2c_start();
i2c_write(0b10100011); // Sequential read from eeprom 1
printf(lcd_putc,"\fBegin read <45 ");
for(j=0; j <= 4000; j++){
data = i2c_read();
portb = data;
}
}
|
|
|
|
Guest
|
|
Posted: Sun Apr 09, 2006 8:56 am |
|
|
Just to add - I get the address (27E0) from the programming software (PonyProg) ... the 24LC256 contains 16 bits in its addresses.
SophE |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Apr 09, 2006 1:35 pm |
|
|
Quote: | Hi- I am trying to read from a specific address inside an i2C 24LC256 eeprom. |
I have two suggestions:
1. CCS has a driver for the 24LC256. It works. It's available. Use it.
There is no point in re-inventing the wheel.
It's called 24256.C and it's in this folder:
c:\Program Files\Picc\Drivers
2. When you use CCS functions, you need to read the CCS manual
before you use them, to see the data type and size of the parameters
that can be passed to the function.
Download the March 2006 manual here:
http://www.ccsinfo.com/downloads/ccs_c_manual.pdf
If you look in the manual for "i2c write", you see this:
Quote: | I2C_WRITE()
data is an 8 bit int
Syntax: i2c_write (data) |
|
|
|
Sophi
Joined: 14 Jun 2005 Posts: 64
|
|
Posted: Sun Apr 09, 2006 6:50 pm |
|
|
Thanks for the link and suggestions PCM.
I have read all functions.
I thought I would not need the driver since all I am doing is reading.
The data sheet seems fairly straighforward on the steps to follow, except...
how to access a specific address? Possible in CCS C? Not possible?
SophE |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Sun Apr 09, 2006 7:35 pm |
|
|
Sure its possible and the code is already done for you! I guess you didn't look at the driver file. |
|
|
|