cancel
Showing results for 
Search instead for 
Did you mean: 

how-to-erase-and-overwrite-data-in-spi-eeprom

MSank
Associate

I am using WinBond W25Q64JV SPI Flash chip for storing data and micro controller is STM32F101RCT6. When i am try to store the data in Winbond chip it is working fine i can able to read and write data in winbond chip but if i want to overwrite the new data in same address it is not overwrite and it is giving the old data that is new data is not written in same memory.If i use the erase option it is erase all data in all address location i am unable to erase particular address data. After all address data erased i can able to write the new data but i am losing the data in all other locations so please guide me to overwrite the new data in same address location/ Erase option for particular address my code is below

HAL_GPIO_WritePin(CHIP_SELECT_GPIO_Port, CHIP_SELECT_Pin, GPIO_PIN_SET);

HAL_Delay(1000);

HAL_GPIO_WritePin(CHIP_SELECT_GPIO_Port, CHIP_SELECT_Pin, GPIO_PIN_RESET);

Spi_data[0]=0x06; //Write Enable

HAL_SPI_Transmit(&hspi2,Spi_data,1,1000);

HAL_GPIO_WritePin(CHIP_SELECT_GPIO_Port, CHIP_SELECT_Pin, GPIO_PIN_SET);

HAL_GPIO_WritePin(CHIP_SELECT_GPIO_Port, CHIP_SELECT_Pin, GPIO_PIN_RESET);

Spi_data[0]=0x02; //Page Program

Spi_data[1]=0x00;

Spi_data[2]=0x10;

Spi_data[3]=0x14;

Spi_data[4]=0x43;

HAL_SPI_Transmit(&hspi2,Spi_data,5,10000);

HAL_GPIO_WritePin(CHIP_SELECT_GPIO_Port, CHIP_SELECT_Pin, GPIO_PIN_SET);

HAL_GPIO_WritePin(CHIP_SELECT_GPIO_Port, CHIP_SELECT_Pin, GPIO_PIN_RESET);

Spi_data[0]=0x03;//Read Data

Spi_data[1]=0x00;

Spi_data[2]=0x10;

Spi_data[3]=0x14;

HAL_SPI_Transmit(&hspi2,Spi_data,4,100);

HAL_SPI_Receive(&hspi2,GSdata,4,100);

HAL_GPIO_WritePin(CHIP_SELECT_GPIO_Port, CHIP_SELECT_Pin, GPIO_PIN_SET);

when i am try to overwrite the new data in 0x1014 location it is not overwritten if i am use the following erase option it is erase all memory address data

HAL_GPIO_WritePin(CHIP_SELECT_GPIO_Port, CHIP_SELECT_Pin, GPIO_PIN_RESET);

Spi_data[0]=0x20;//Erase

Spi_data[1]=0x00;

Spi_data[2]=0x10;

Spi_data[3]=0x14;

HAL_SPI_Transmit(&hspi2,Spi_data,4,1000);

HAL_GPIO_WritePin(CHIP_SELECT_GPIO_Port, CHIP_SELECT_Pin, GPIO_PIN_SET);

please guide me to overwrite the new data in same address/Erase option for particular address

5 REPLIES 5
S.Ma
Principal

Invest energy to read the datasheet of the serial memory.

First FLASH and EEPROM are not the same thing, especially for what you noticed.

EEPROM doesn't need to erase a sector, FLASH does, through specific commands.

Sector size varies. FLASH exist in 2 technos NOR and NAND.

When a sector is erased, you should either backup in RAM or another erase sector (which burns the number of times you can erase without data corruption creeping up).

MSank
Associate

Thanks for the reply now i understand so if i want to change single byte data i have to first move the data to another address and then after erasing the old address again move the data to the old location is that correct

S.Ma
Principal

Have you just read until thepage 4 of the spec?

https://www.winbond.com/resource-files/w25q64jv%20spi%20%20%20revc%2006032016%20kms.pdf

The W25Q64JV array is organized into 32,768 programmable pages of 256-bytes each. Up to 256 bytes can be programmed at a time. Pages can be erased in groups of 16 (4KB sector erase), groups of 128 (32KB block erase), groups of 256 (64KB block erase) or the entire chip (chip erase). The W25Q64JV has 2,048 erasable sectors and 128 erasable blocks respectively. The small 4KB sectors allow for greater flexibility in applications that require data and parameter storage. (See Figure 2.) 

So you can write max 256 byte and can erase min 4 bkyte. Clear?

Nredd.1
Associate III

Hi,

how do u know the how many pages of data availbile or not?

>>how do u know the how many pages of data available or not?

What's the context here, this is a year old thread.

The data sheet for the device provides specific details on the geometry.

If you use multiple different devices, you can read the JEDEC ID

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..