2015-02-23 03:39 PM
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); }2015-02-23 04:33 PM
Does the device have some expectation of you reading/clearing some status after the erase?
2015-02-23 05:12 PM
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? Bob2015-02-23 05:43 PM
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?2015-02-23 05:52 PM
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?
2015-02-24 12:27 AM
Hi Clive,
Putting it on the analyser today...will let you know. Yes always the first write after the erase. Bob2015-02-24 11:24 AM
Hi Clive,
Good point ...Reading location twice returns the correct value so write is OK. Do you have a possible cause in mind? Bob2015-02-24 12:40 PM
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.2015-02-26 05:12 AM
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? Bob2015-02-26 05:58 AM
What is WriteEnable()?
JW