Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Thread Closed: Issue successfully resolved

???
06/04/04 05:56
Read: times


 
#71704 - Serial EEPROM problem
I'm writting to AT24C128 serial eeprom as shown by the datasheet and the read command shown below works, while the write command doesn't. I wrote to the chip using external programmer and it was ok, reading from it works fine, but writting doesn't. Can anyone check this code for me ?
/******************************************************************************
* NAME:        readAt                                                         *
* DESCRIPTION: This function reads a byte at a specified address              *
******************************************************************************/
unsigned char readAt(unsigned int address)
{
    unsigned char data1;
    i2c_Start();                    // make a start condition
    i2c_SendAddress(ROM, 0);        // 0 write 1 read
    i2c_ReadAcknowledge();          // wait for acknowledge from eeprom
    i2c_SendByte(address >> 8);     // send upper byte of address to eeprom
    i2c_ReadAcknowledge();          // wait for acknowledge from eeprom
    i2c_SendByte(address & 0xff);   // send lower byte of address to eeprom
    i2c_ReadAcknowledge();          // wait for acknowledge from eeprom
    i2c_Start();                    // make a start condition
    i2c_SendAddress(ROM, 1);        // issue read command
    i2c_ReadAcknowledge();          // wait for acknowledge from eeprom
    data1 = (char)i2c_ReadByte();   // get data out of eeprom
    i2c_Stop();                     // finish the process
    return(data1);                  // give data back to caller
}

/******************************************************************************
* NAME:        writeAt                                                        *
* DESCRIPTION: This function writes a byte to a specified address             *
******************************************************************************/
void writeAt(unsigned int addr, unsigned char data)
{
    i2c_Start();                // start condition
    i2c_SendAddress(ROM, 0);    // 0 = write, 1 = read, ROM is 0xA0 
    i2c_ReadAcknowledge();      // wait for acknowledge from EEPROM
    i2c_SendByte(addr >> 8);    // send upper address byte
    i2c_ReadAcknowledge();      // wait for acknowledge from EEPROM
    i2c_SendByte(addr & 0xff);  // send lower address byte
    i2c_ReadAcknowledge();      // wait for acknowledge from EEPROM
    i2c_SendByte(data);         // write the data to EEPROM
    i2c_ReadAcknowledge();      // wait for acknowledge from eeprom
    i2c_Stop();                 // stop
}

I connected the WP to gnd, but the chip seems not to write either for error in the datasheet or I tried to make a memory reset function as indicated by the datasheet but I still have this problem.
Thanks
Mahmood

List of 18 messages in thread
TopicAuthorDate
Serial EEPROM problem            01/01/70 00:00      
   RE: Serial EEPROM problem            01/01/70 00:00      
      RE: Serial EEPROM problem            01/01/70 00:00      
         RE: Serial EEPROM problem            01/01/70 00:00      
   RE: Serial EEPROM problem            01/01/70 00:00      
      RE: Serial EEPROM problem            01/01/70 00:00      
         RE: Serial EEPROM problem            01/01/70 00:00      
         RE: Serial EEPROM problem            01/01/70 00:00      
   RE: Serial EEPROM problem            01/01/70 00:00      
      RE: Serial EEPROM problem            01/01/70 00:00      
   RE: Serial EEPROM problem            01/01/70 00:00      
      RE: Serial EEPROM problem            01/01/70 00:00      
         RE: Serial EEPROM problem            01/01/70 00:00      
   RE: Serial EEPROM problem            01/01/70 00:00      
   RE: Serial EEPROM problem            01/01/70 00:00      
      RE: Serial EEPROM problem            01/01/70 00:00      
         RE: Serial EEPROM problem            01/01/70 00:00      
   Problem Solved!!!!!            01/01/70 00:00      

Back to Subject List