In serial EEPROM can i write the data in different locations or it should be written in sequence?
For example,
If i write the first data - 0x05 in location 0x0000, can i write the second data in 0xF000 or should i write the second data in 0x0001.
Hard to say without seeing your code.
Non-sequential addresses, each with a separate write transaction. Each transaction fully setting the device's internal address with write commencing after the stop condition starting a self-timed write, the completion of which you must either ACK-poll or implement a fixed worst-case delay.
My coding is,
#define EEPROM_WR 0xA2 #define EEPROM_RD 0xA3 sbit SCLK = P1^1; sbit SDA = P1^2; unsigned int ptr;
typedef union { float f; char b[4]; } fval;
void EEPROM_Location(unsigned int x) { ptr = x; }
void EEPROM_WrByte(unsigned char x) { I2C_Start(); //START I2C PROTOCOL I2C_Write(EEPROM_WR); //CTRL WORD FOR WRITE MODE I2C_Write((char)(ptr>>8)); //HIGH ADDRESS BYTE I2C_Write((char)ptr); //LOW ADDRESS BYTE I2C_Write(x); //WRITE THE DATA I2C_Stop(); ptr++; LongDelay(15); return; }
void EEPROM_WrInt(unsigned int x) { I2C_Start(); //START THE I2C PROTOCOL I2C_Write(EEPROM_WR); //CTRL WORD FOR WRITE MODE I2C_Write((char)(ptr>>8)); //HIGH ADDRESS BYTE I2C_Write((char)ptr); // LOW ADDRESS BYTE I2C_Write((char)(x>>8)); //HIGH DATA BYTE I2C_Write((char)(x)); // LOW DATA BYTE I2C_Stop(); ptr+=2; LongDelay(15); return; }
This routine is called as "eeprom.c" The main function code is,
extern unsigned int ptr;
void main(void) { unsigned char a,b,c; unsigned char x,y,z; a = 0x32; b = 0x45; c = 0x56; ptr = 0x0000; EEPROM_Location(ptr); EEPROM_WrByte(a); LongDelay(15); EEPROM_Location(ptr); EEPROM_WrByte(b); LongDelay(15); EEPROM_Location(ptr); EEPROM_WrByte(c); LongDelay(15); ptr = 0x0000; EEPROM_Location(ptr); x = EEPROM_RdByte(); LongDelay(15); EEPROM_Location(ptr); y = EEPROM_RdByte(); LongDelay(15); EEPROM_Location(ptr); z = EEPROM_RdByte(); LongDelay(15); }
With ptr = 0x0000, if i print the values x,y,z the output is correct. If i initialize my ptr = 0xF000, and write the data into it and read the data from same location, no output. I dont know where is the problem?
I don't see EEPROM_RdByte().
"... and read the data from same location, no output."
What does "no output" mean?
Thank you.
I had solved the problem.