Search code examples
c#spiftdieeprom

Read EEPROM via SPI (C232HM)


I want to read a M95128-DRMF4TG/K EEPROM with a C232Hm MPSSE cable, with contains a C232H MPSSE controller. This is my code (C#):

private void ReadSPI(byte[] byteArray, int adress) //adress is 0x0100, bytearray has 998 Elements for 998 bytes to read
{
    byte msbAdress = (byte)(adress >> 8);
    byte lsbAdress = (byte)adress;
    // First send the adress needed to the EEPROM
    byte[] eepromSendData = new byte[] //Sending the EEPROM the command, that it shall return the data from the specific adress
    {
        0x10, 0x02, 0x00,
        0x03, msbAdress, lsbAdress
    };
    ftStatus = ftdiDevice.Write(eepromSendData, eepromSendData.Length, ref bytesWritten);

    
    byte msbLength = ((byte)(byteArray.Length >> 8));
    byte lsbLength = (byte)byteArray.Length;
    
    byte[] readCommand = new byte[] // readCommand for the C232H controller
    {
        0x20, lsbLength, msbLength
    };
    ftStatus = ftdiDevice.Write(readCommand, readCommand.Length, ref bytesWritten);
    ftStatus = ftdiDevice.Read(byteArray, (uint)byteArray.Length, ref bytesRead);

    if (ftStatus != FTDI.FT_STATUS.FT_OK || bytesRead != byteArray.Length)
    {
        MessageBox.Show("Error reading SPI");
        return;
    }
    bytesWritten = 0;
    bytesRead = 0;
}

My EEPROM returns only 0xFF for every byte.

Writing the readCommand is necessary, cause it activates the clock. Writing only ftdiDevice.Read will result in a freezing of the programm.

Reading different sections of the EEPROM ended in the same result. The eepromSendData array, which commands the EEPROM tho send data from the adress in that array, gets to the EEPROM as it should. CS ist active. Clock can be measuered. The SOMI Pin is on 2.4V (Vcc is 3.3V) all the time, so as I see it, the EEPROM simply does not send any data.

Datasheet EEPROM


Solution

  • Found the problem. My coworker, who gave me the EEPROM, told me, that it contains data. But after searching for the root cause it was showed, that none of the EEPROM he gave me, contained data. Sry for the waste of time guys