[51] peculiar Problem with AT24C512.

Status
Not open for further replies.

nitheeshthavakkara

Newbie level 4
Joined
Sep 11, 2009
Messages
7
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Location
mumbai
Visit site
Activity points
1,349
Hi..

I have done my interfacing of 24C512 with 89c55, Reading writing everything working fine..
But the problem is i tried to write alphabet on a particular location; say 0x00A0... writing done successfully; and when i tried to read it back instead of 0x00A0, same data is available at 0x01A0,0x02A0,... like that...
Please help me to resolve this problem..

eeprom routines are given..

Code:
#include "ports.h"
#include "eeprom.h"
#include "i2c.h"
#include "lcd.h"

#define EEPROMS_ID 0xA0	/* Microchip 24xx512 */

unsigned char EEPROM_get(unsigned int addr)
{
	unsigned char dat;	

	I2C_start();             // Start i2c bus
	msdelay(2) ; 
	I2C_write(EEPROMS_ID);   // Connect to EEPROM 
	I2C_write(addr&0xF0);	 // Request RAM address (Hight byte) 
	I2C_write(addr&0x0F);	 // Request RAM address (Low byte) 
	I2C_start();			 // Start i2c bus 
	msdelay(2) ;
	I2C_write(EEPROMS_ID+1); // Connect to EEPROM for Read 
	dat = I2C_read();		 // Receive data 
	I2C_noack();
	msdelay(2) ;
	I2C_stop();				 // Stop i2c bus 
    return dat;			
}
void EEPROM_set(unsigned int addr, unsigned char val)
{
	I2C_start(); 
	msdelay(2) ;
	I2C_write(EEPROMS_ID);   
	I2C_write(addr&0xF0);	
	I2C_write(addr&0x0F);	 
	I2C_write(val);	
	msdelay(2) ;		
	I2C_stop();           	
}
 





Hi ,
you made a mistake at the addressing the memory chip at reading and writing.



the has need to modify like below:


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
void eeprom_write(U16 mem_adr, U8 dat)   //g_random_write(device addr,Local addr,data)
{
    union LVAL
    {
        U32 LVAL;
        U8 CVAL[4];
 
    }LV;
    LV.LVAL = mem_adr;
 
   eeprom_i2c_start();
   eeprom_i2c_out_byte(0xa0);                                //device address with write command
   eeprom_i2c_ack(); 
   eeprom_i2c_out_byte(LV.CVAL[1]& 0xff);                   //local address ie,the location to be write the data to the EEPROM..
   eeprom_i2c_ack();
   eeprom_i2c_out_byte(LV.CVAL[0] & 0xff);                  //local address ie,the location to be write the data to the EEPROM..
   eeprom_i2c_ack();
   eeprom_i2c_out_byte(dat);                            // and finally the data
   eeprom_i2c_ack();
   eeprom_i2c_stop();   
   Delay_ms(10);
}
 
 
 
U8 eeprom_read(U16 mem_adr)  //g_random_read(device addr,local addr)
{
   U8 y;
    union LVAL
    {
        U32 LVAL;
        U8 CVAL[4];
        }LV;
        LV.LVAL = mem_adr;
 
   eeprom_i2c_start();
   eeprom_i2c_out_byte(0xa0);             // device address with write command  
   eeprom_i2c_ack();
   eeprom_i2c_out_byte(LV.CVAL[1]& 0xff);                   //local address ie,the location to be write the data to the EEPROM..
   eeprom_i2c_ack();
   eeprom_i2c_out_byte(LV.CVAL[0] & 0xff);   // local address ie,the location to be Read the data from the EEPROM.
   eeprom_i2c_ack();
   eeprom_i2c_start();                   // no intermediate stop
   eeprom_i2c_out_byte(0xa1);            // Finaly the Read operation
   eeprom_i2c_ack();    
   y=eeprom_i2c_in_byte();                // Receive the Data from the particular addr.   
   eeprom_i2c_stop();
   return(y);
}






This My working code try this your problem get solved

mistakes you have done.....................

the 16 bit address in your code was not written in you code


this might be solve your problem
 
Last edited by a moderator:

hello,

AT24C512 is 64K bytes
why an unsigned long for the adress.. (32 bits)
unsigned int (16 bits) can reach the maxi adress : 65535
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…