| View previous topic :: View next topic   | 
	
	
	
		| Author | 
		Message | 
	
	
		
			dbrown
 
 
  Joined: 24 Jul 2004 Posts: 20
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				| 24lc515 eeprom question | 
			 
			
				 Posted: Tue Dec 27, 2005 12:14 am     | 
				     | 
			 
			
				
  | 
			 
			
				I am trying to create a function that will use the eeprom page write capabilities to write "a's" to all the memory to indicate that it has been changed. The problem I have is it seems to write to every second page. I have attached a copy of the function, and a copy of the output as read from the eeprom. For the sake of saving time during testing I was only trying to write "a's" to the first 20 pages. Any help would be greatly appreciated.
 
 
 	  | Code: | 	 		  page_write_eeprom(){
 
int1 status;
 
long p=0;
 
int cnt=0;
 
int16 address=0;     
 
while(p<20)
 
   {
 
      
 
              i2c_start();
 
              i2c_write(0xa0);
 
              address=(p*64);  
 
              i2c_write(address>>8);
 
              i2c_write(address);
 
              status=i2c_write(0xa0);
 
         
 
      while(cnt<=63)
 
         {
 
            i2c_write('a');
 
            ++cnt;
 
         }
 
      cnt=0;
 
      i2c_stop();     
 
      ++p; 
 
   }
 
lcd_cmd(1);
 
printf(lcd_puts,"finished");
 
enable_interrupts(int_rtcc);
 
} | 	  
 
 
 
 
Here is the retrieved data:
 
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
 
zzzzzzzzzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
 
zzzzzzzzzzzzzzzzzzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
 
zzzzzzzzzzzzzzzzzzzzzzzzzzzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaazzzzzzzzzzzzzzzzzzzzzzzzzzzz
 
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaazzzzzzzzzzzzzzzzzzz
 
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaazzzzzzzzzz
 
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz
 
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
aaaaaaaazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
 
 
Thank you
 
 
David Brown | 
			 
		  | 
	
	
		  | 
	
	
		
			PCM programmer
 
 
  Joined: 06 Sep 2003 Posts: 21708
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Tue Dec 27, 2005 1:13 am     | 
				     | 
			 
			
				
  | 
			 
			
				According to the 24LC515 data sheet, a write operation will take up to
 
5 ms to complete.   You must either do a static delay of 5 ms (by using
 
delay_ms(5)) or you must do "ack polling" after every write operation.
 
(This "write operation" can be either a byte write or a page write.
 
The write operation is terminated when you do the i2c_stop().
 
At that point, you must do the delay or the ack polling).
 
 
See the CCS driver file, 24256.C, for an example of ack polling.
 
The file is in this folder:  c:\Program Files\Picc\Drivers
 
 
Also, be aware that the first half of the 24LC515 is addressed with
 
a control byte of 0xA0, and the 2nd half with 0xA8.   This is in the
 
data sheet. | 
			 
		  | 
	
	
		  | 
	
	
		
			dbrown
 
 
  Joined: 24 Jul 2004 Posts: 20
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				| 25LC515 help | 
			 
			
				 Posted: Tue Dec 27, 2005 1:21 pm     | 
				     | 
			 
			
				
  | 
			 
			
				PCM Programmer
 
 
Thank you for your help, I made the change and it works just fine. Thanks also for pointing out the separation, I missed that when I read the data sheet.
 
 
Thanks again
 
 
David Brown | 
			 
		  | 
	
	
		  | 
	
	
		
			dbrown
 
 
  Joined: 24 Jul 2004 Posts: 20
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				| 24LC515 | 
			 
			
				 Posted: Tue Dec 27, 2005 5:13 pm     | 
				     | 
			 
			
				
  | 
			 
			
				I just tried to write to the second half of the eeprom, however I have had no success. I understand that I need to change the control word from A0 to A8, does this apply to checking status? I also assume that the address for location 0 of the second half is actually 32768, is this correct? The write function works for the first half, however it hangs when I try to write to the second half. I have attached the code that I am using for the write.
 
 
 	  | Code: | 	 		  
 
void write_ext_eeprom(int16 address){
 
short int status;
 
INT data;
 
int end;
 
int i;
 
int ctrl_data;
 
 
if(address<=32767){
 
ctrl_data=0xa0;
 
}else{
 
ctrl_data=0xa8;
 
address=address-32768;
 
}
 
 
        end=(strlen(t)-1);
 
       for(j=0;j<=end;){
 
            data=t[j];
 
 
            i2c_start();
 
            status=i2c_write(ctrl_data);
 
               while(status==1)
 
                     {
 
                         i2c_start();
 
                         status=i2c_write(ctrl_data);
 
                     }
 
printf("Address %lu\r\n",address);   
 
   i2c_start();
 
   i2c_write(ctrl_data);
 
   i2c_write(address>>8);
 
   i2c_write(address);
 
   i2c_write(data);
 
   i2c_stop();
 
 
address=address+1;
 
j++;
 
}
 
 
 
printf("Write complete");
 
lcd_cmd(1);
 
enable_interrupts(int_rda);
 
enable_interrupts(int_rtcc);
 
}
 
 | 	 
  | 
			 
		  | 
	
	
		  | 
	
	
		
			PCM programmer
 
 
  Joined: 06 Sep 2003 Posts: 21708
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Tue Dec 27, 2005 5:54 pm     | 
				     | 
			 
			
				
  | 
			 
			
				Is this the real routine, because I see the following problems
 
 
1.  Variables are not declared, such as 'j'.
 
 
2.  The CCS driver, 24256.C, has the ack polling code placed
 
     after the end of the write operation, not at the beginning
 
     as you are doing.
 
 
3.  According to the 24LC515 data sheet, the A15 bit of the 16-bit
 
     address is ignored by the eeprom.   So you don't have to do
 
     that subtraction that you're doing at the start of the routine.
 
 
4.  There are a few other oddities.   I'm not sure why you have
 
     taken the 'j++' out of the for(;;) loop and stuck it at the end
 
     of the routine.    Declaring 'status' as a short int actually 
 
     increases the amount of generated code and doesn't gain
 
     anything. | 
			 
		  | 
	
	
		  | 
	
	
		
			dbrown
 
 
  Joined: 24 Jul 2004 Posts: 20
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				| 24LC515 | 
			 
			
				 Posted: Tue Dec 27, 2005 6:18 pm     | 
				     | 
			 
			
				
  | 
			 
			
				Hello PCM
 
 
I only attached a portion of the entire program.  I did have 'J' declared, it was declared as a global. I moved the polling to the end of the write but it still hangs. I copied the declarations for the short int from the CCS 24256.C driver, I did not know it created more code to use a short. I still do not understand if I need to change the control word from A0 to A8 during ack polling, for the second 256K. I attached the revised code.
 
 
 	  | Code: | 	 		  
 
void write_ext_eeprom(int16 address){
 
int status;
 
INT data;
 
int end;
 
int i;
 
int ctrl_data;
 
if(address<=32767){
 
ctrl_data=0xa0;
 
}else{
 
ctrl_data=0xa8;
 
}
 
        end=(strlen(t)-1);
 
       for(j=0;j<=end;j++){
 
           data=t[j];                        
 
   i2c_start();
 
   i2c_write(ctrl_data);
 
   i2c_write(address>>8);
 
   i2c_write(address);
 
   i2c_write(data);
 
   i2c_stop();
 
   i2c_start();
 
status=i2c_write(ctrl_data);  
 
while(status==1)
 
                     {
 
                         i2c_start();
 
                         status=i2c_write(ctrl_data);
 
                     }
 
printf("address %lu\r\n",address);
 
address=address+1;
 
}
 
printf("Write complete");
 
lcd_cmd(1);
 
enable_interrupts(int_rda);
 
enable_interrupts(int_rtcc);
 
}
 
 
 | 	  
 
 
Thanks for the help
 
 
Dave B | 
			 
		  | 
	
	
		  | 
	
	
		
			PCM programmer
 
 
  Joined: 06 Sep 2003 Posts: 21708
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Tue Dec 27, 2005 6:46 pm     | 
				     | 
			 
			
				
  | 
			 
			
				The 24LC515 data sheet says:
 
 	  | Quote: | 	 		  
 
Note: Care must be taken when polling the
 
24LC515. The control byte that was used
 
to initiate the write needs to match the
 
control byte used for polling. | 	 
  | 
			 
		  | 
	
	
		  | 
	
	
		
			dbrown
 
 
  Joined: 24 Jul 2004 Posts: 20
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				| 24lc515 | 
			 
			
				 Posted: Tue Dec 27, 2005 6:53 pm     | 
				     | 
			 
			
				
  | 
			 
			
				Thanks for the help, I made a stupid mistake with the IC. I somehow managed to install a 24LC256, rather than the '515.
 
 
Thanks for your time
 
 
Dave | 
			 
		  | 
	
	
		  | 
	
	
		 |