cancel
Showing results for 
Search instead for 
Did you mean: 

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

stenasc
Senior
Posted on February 24, 2015 at 00:39

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 >> 😎 & 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 >> 😎 & 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);         

}
15 REPLIES 15
Posted on February 24, 2015 at 01:33

Does the device have some expectation of you reading/clearing some status after the erase?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
stenasc
Senior
Posted on February 24, 2015 at 02:12

Hi Clive,

Flash is an SST25VF016B. I wait until the status register indicates that the erase operation is complete. If flash wasn't properly erased, would there not be issues with other memory locations instead of just the first one I write to?

Bob

Posted on February 24, 2015 at 02:43

I'm not say it doesn't erase properly. You're telling me it doesn't accept the first write immediately after the erase. When the erase completes it clears the write enable.

Is that write corrupted, or just not occurring? Is there a pattern to the corruption (bits, bits vs address, etc)? Can you confine the failing transaction on the scope/analyzer? What is the status when it fails?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on February 24, 2015 at 02:52

Perhaps the WriteEnable() isn't being accepted, or is lost? What if you do it twice? Or do a read-back check of the enable?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
stenasc
Senior
Posted on February 24, 2015 at 09:27

Hi Clive,

Putting it on the analyser today...will let you know. Yes always the first write after the erase.

Bob

stenasc
Senior
Posted on February 24, 2015 at 20:24

Hi Clive,

Good point ...Reading location twice returns the correct value so write is OK. Do you have a possible cause in mind?

Bob

Posted on February 24, 2015 at 21:40

Well these devices have very little intelligence, they are little state machines, stuff shifts in, stuff shifts out. I'd look very carefully at the data on the wire, the clocks, and the placement of the chip select. So if something terminates too early, shifts too many, or too few cycles.

You have the conditions quite well constrained, so you can capture and focus on anything that looks anomalous.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
stenasc
Senior
Posted on February 26, 2015 at 14:12

Hi Clive.

I have to perform a write enable just prior to reading..see read function. There is nothing in the datasheet, that tells me I need to do this but without it I can't read anything. You ever come across this before?

Bob

Posted on February 26, 2015 at 14:58

What is WriteEnable()?

JW