Hello,
I want to interface 24LC1025 with atmega32. 24LC1025 is divided in two block of 512kb and in control frame there is a bit block select bit to select the block. I can read and write first block without any problem(random read and write).
But when I try to read second block I getting 255. I am sure my I2C rutains are correct because as I say, I can read and write on first block. This is my code. Please help to solve the problem.
//Microcontroller- atmega32 //Compiler-WINAVR 20100110 ,AVR STDIO 7 //CRESTAL- FREQ-11.0592Mhz void main(void) { unsigned char log_data[5]; EEPROM_WriteByte_1Mb(100,10,0); //work fine EEPROM_WriteByte_1Mb(200,20,0); //work fine EEPROM_WriteByte_1Mb(300,30,1); //not working EEPROM_WriteByte_1Mb(400,40,1); //not working while(1){ log_data[0]= EEPROM_ReadByte_1Mb(100,0); //Read block 0, this by setting block select bit =0,this is working fine log_data[1]= EEPROM_ReadByte_1Mb(200,0); log_data[2]= EEPROM_ReadByte_1Mb(300,1); //Read block 1, this by setting block select bit =1,this not work log_data[3]= EEPROM_ReadByte_1Mb(400,1); ms(100); } } unsigned char check_frame; //This is for checking value of control frame, When I select block 0, here value is A0, this working fine //when I select block 1, here value is A8, this not working. /**************** Input- address,data,block bit output- non ****************/ void EEPROM_WriteByte_1Mb(unsigned int eeprom_Address, unsigned char eeprom_Data, unsigned char block) { unsigned char address_wh,address_wl; unsigned char Page_Number=0x00; if(block==0){ Page_Number=0x00; //select first block ,first 512Kb } else if(block==1){ Page_Number=0x04; //select second block ,second 512Kb } else{ Page_Number=0x00; //Default select block 1 } address_wh= ((eeprom_Address>>8) & 0x00FF); //break int to char address_wl= (eeprom_Address & 0X00FF); I2C_Start(); // Start i2c communication I2C_Write(EEPROM_ID|(Page_Number<<1)); // connect to 24LC1025 and above by sending its ID on I2c Bus check_frame=(EEPROM_ID|(Page_Number<<1)); I2C_Ack(); I2C_Write(address_wh); //Send address high I2C_Ack(); I2C_Write(address_wl); //Send address low I2C_Ack(); I2C_Write(eeprom_Data); // Write the data at specified address I2C_Ack(); I2C_Stop(); // Stop i2c communication after Writing the data ms(5); //Should be 5 ms delay in every random write return; } /**************** Input- address and block bit output- unsigned char data ****************/ unsigned char EEPROM_ReadByte_1Mb(unsigned int eeprom_Address,unsigned char block) { unsigned char eeprom_Data; //,address_h,address_l; unsigned char address_rh,address_rl; unsigned char Page_Number=0x00; if(block==0){ Page_Number=0x00; //select first block ,first 512Kb } else if(block==1){ Page_Number=0x04; //select second block ,second 512Kb } else{ Page_Number=0x00; //Default select block 1 } address_rh= ((eeprom_Address>>8) & 0x00FF); //break int to char address_rl= (eeprom_Address & 0X00FF); I2C_Start(); // Start i2c communication I2C_Write(EEPROM_ID|(Page_Number<<1)); // connect to AT24LC1025 and above(write) by sending its ID on I2c Bus I2C_Ack(); I2C_Write(address_rh); // address high I2C_Ack(); I2C_Write(address_rl); // address low I2C_Ack(); I2C_Start(); // Start i2c communication I2C_Write(0xA1|(Page_Number<<1)); // connect to 24lc1025(read) by sending its ID on I2c Bus I2C_Ack(); eeprom_Data = I2C_Read(); // Read the data from specified address I2C_NoAck(); I2C_Stop(); // Stop i2c communication after Reading the data us(10); return (eeprom_Data); // Return the Read data }