0
\$\begingroup\$

I am trying to write the data into the NOR flash but for some reason it is taking some random/garbage data . First i tried to erase the sector then i read the data from the same location which i have erased so i get some garbage data so it seems that it does not erase the data .below is the code called from main

uint8_t datatemp[128];

 W25QXX_erase_Sector(0);
 W25QXX_Read(datatemp,0 , 128);


void W25QXX_erase_Sector(uint32_t Dst_Addr)
{
    // Monitor flash erase, test
    printf("fe:%lx\r\n",Dst_Addr);
    Dst_Addr = Dst_Addr * 4096;
    W25QXX_Write_Enable(); //SET WEL
    W25QXX_Wait_Busy();
    HAL_GPIO_WritePin(GPIOA,GPIO_PIN_4,GPIO_PIN_RESET); //Enable device
    SPI1_ReadWriteByte(W25q64_SectorErase); //Send sector erase instruction
    SPI1_ReadWriteByte((uint8_t)((Dst_Addr)>>16)); //Send 24bit address
    SPI1_ReadWriteByte((uint8_t)((Dst_Addr)>>8));
    SPI1_ReadWriteByte((uint8_t)Dst_Addr);
    HAL_GPIO_WritePin(GPIOA,GPIO_PIN_4,GPIO_PIN_SET); //Cancel the chip selection
    W25QXX_Wait_Busy(); //Wait for erasure completion
}

void W25QXX_Read(uint8_t* pBuffer, uint32_t ReadAddr, uint16_t NumByteToRead)
{
    uint16_t i;

    HAL_GPIO_WritePin(GPIOA,GPIO_PIN_4,GPIO_PIN_RESET); //Enable device
    SPI1_ReadWriteByte(W25q64_ReadData); //Send read command
    SPI1_ReadWriteByte((uint8_t)((ReadAddr)>>16)); //Send 24bit address A23-A16
    SPI1_ReadWriteByte((uint8_t)((ReadAddr)>>8)); //A15-A8
    SPI1_ReadWriteByte((uint8_t)ReadAddr); // A7-A0
    for(i = 0; i < NumByteToRead; i++)
    {
        pBuffer[i]=SPI1_ReadWriteByte(0xff); //cyclic reading- 0XFF
    }
    HAL_GPIO_WritePin(GPIOA,GPIO_PIN_4,GPIO_PIN_SET); //Cancel the chip selection
}
\$\endgroup\$
  • \$\begingroup\$ hi thanks for the reply i am starting to write at 0th location so directly passing as 0 in erase sector function \$\endgroup\$ – Ethane Das Mar 11 '19 at 8:00
  • \$\begingroup\$ I'm just talking about this line Dst_Addr = Dst_Addr * 4096;. Could you post the setup of your SPI? Does reading the menufacturer / device id work? \$\endgroup\$ – po.pe Mar 11 '19 at 8:12
  • \$\begingroup\$ yes it work and its give me manufacture id = 0xEF, product id = 0x4017 \$\endgroup\$ – Ethane Das Mar 11 '19 at 8:22
  • \$\begingroup\$ hspi1.Instance = SPI1; hspi1.Init.Mode = SPI_MODE_MASTER; hspi1.Init.Direction = SPI_DIRECTION_2LINES; hspi1.Init.DataSize = SPI_DATASIZE_8BIT; hspi1.Init.CLKPolarity = SPI_POLARITY_LOW; hspi1.Init.CLKPhase = SPI_PHASE_1EDGE; hspi1.Init.NSS = SPI_NSS_SOFT; hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2; hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB; hspi1.Init.TIMode = SPI_TIMODE_DISABLE; hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; hspi1.Init.CRCPolynomial = 10; if (HAL_SPI_Init(&hspi1) != HAL_OK) \$\endgroup\$ – Ethane Das Mar 11 '19 at 8:23
  • \$\begingroup\$ hi , i am referring the code form the se link github.com/SmartHW/Iov/blob/master/HARDWARE/W25QXX/w25qxx.c \$\endgroup\$ – Ethane Das Mar 11 '19 at 8:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.