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

24LC256 Read from specific address

 
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

24LC256 Read from specific address
PostPosted: Sun Apr 09, 2006 7:18 am     Reply with quote

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








PostPosted: Sun Apr 09, 2006 8:56 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Apr 09, 2006 1:35 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Apr 09, 2006 6:50 pm     Reply with quote

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

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

PostPosted: Sun Apr 09, 2006 7:35 pm     Reply with quote

Sure its possible and the code is already done for you! I guess you didn't look at the driver file.
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