AnsweredAssumed Answered

First write into any SPI flash address does not match read value

Question asked by carter.bob on Feb 24, 2015
Latest reply on Mar 2, 2015 by carter.bob
Hello,

After a device or sector erase, whenever I write into the first SPI flash address and then read it back, the val ue read does not match the written value. All other wrire and reads to subsequent memory locations are fine. It is just the very first address. I thought it may have been to do with page boundaries but I selected the first address to be in the middle of a page and it still occurs. Below are my read and write routines. Can anyone provide any insite to why this is occurring?

Kind Regards
Bob


uint8_t SPI_Flash_Write(uint8_t ins, uint32_t address, uint8_t data)
{
uint8_t address_byte;
    
    // Now write the actual data tht we want
    WriteEnable();    
    EEPROM_CS_LOW;    
    SPI_SendByte(ins);
    address_byte = (address >> 16) & 0x0000FF;
    SPI_SendByte(address_byte);
    address_byte = (address >> 8) & 0x0000FF;    
    SPI_SendByte(address_byte);
    address_byte = address & 0x0000FF;    
    SPI_SendByte(address_byte);    
    SPI_SendByte(data);
        if (SPI_I2S_GetFlagStatus(SPIx,SPI_I2S_FLAG_RXNE) == SET)
            SPI_ReceiveData8(SPIx);
        while (SPI_I2S_GetFlagStatus(SPIx, SPI_I2S_FLAG_BSY) == SET);
    EEPROM_CS_HIGH;                
     return (1);
}



uint8_t SPI_Flash_Read(uint8_t ins, uint32_t address)
{
uint8_t spi_rd_data_local = 0;
uint8_t address_byte;    
    
  WriteEnable();
    
  EEPROM_CS_LOW;    
  if (SPI_I2S_GetFlagStatus(SPIx,SPI_I2S_FLAG_RXNE) == SET)
       spi_rd_data_local = SPI_ReceiveData8(SPIx);    
  // Send SPI instruction        
  SPI_SendByte(ins);    
  // Send SPI address H
  address_byte = (address >> 16) & 0x0000FF;    
  SPI_SendByte(address_byte);
  // Send SPI address M
  address_byte = (address >> 8) & 0x0000FF;    
  SPI_SendByte(address_byte);
  // Send SPI address L
  address_byte = address & 0x0000FF;    
  SPI_SendByte(address_byte);
  // Send Dummy Byte for Clocks
  SPI_SendByte(0xFF);
  if (SPI_I2S_GetFlagStatus(SPIx,SPI_I2S_FLAG_RXNE) == SET)
       spi_rd_data_local = SPI_ReceiveData8(SPIx);
  while (SPI_I2S_GetFlagStatus(SPIx, SPI_I2S_FLAG_BSY) == SET);
  EEPROM_CS_HIGH;
  return(spi_rd_data_local);         
}

Outcomes