1
votes

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

2
If you need to rewrite a portion of a sector you can read the entire section into RAM, erase the sector, and then rewrite the modified sector.kkrambo

2 Answers

4
votes

From the product datasheet

8.3 Sector Erase (20h)

The Sector Erase instruction sets all memory within a specified sector (4K-bytes) to the erased state of all 1s (FFh).

This is a flash memory, not an eeprom, therefore there's a minimum erase block size, which is 4 kilobytes. There's no way to erase individual bytes.

0
votes

W25Q64JV has 64 mbit = 8 mbyte each sector has 4 kbytes size then you have 2000 sector or 0x7d0 so the maximum address you can erase is 0x7d0

you want to erase 0x1014 this byte is on sector 2 then you should erase sector 0x2 but every other bytes in this sector erase too you can copy sector 2 in array then erase sector 2 and after that write array in to this sector