Write Byte Function:
void SPI_Flash_WriteByte(unsigned char Data , unsigned long int Address)
{
SPI_Flash_WREN(); //Enable Write Ability
FLASH_CS_PIN = 0; //Enable Flash Chip
SPI_Flash_SendByte(0x02);
SPI_Flash_SendByte((Address & 0xFFFFFF) >> 16); //Send 8 Upper Bits of Address
SPI_Flash_SendByte((Address & 0xFFFF) >> 8); //Send Next 8 Bits
SPI_Flash_SendByte(Address & 0xFF); //Send Last 8 Bits
SPI_Flash_SendByte(Data); //Send Data in Order to Store in Memory
FLASH_CS_PIN = 1; //Enable Flash Chip
SPI_Flash_WRDI(); //Disable Write Ability
}
erase sector Function:
void SPI_Flash_4KBErase(unsigned long int Address)
{
SPI_Flash_WREN(); //Enable Write Ability
FLASH_CS_PIN = 0; //Enable Flash Chip
SPI_Flash_SendByte(0x20); //Send "Chip Erase" Instruction
SPI_Flash_SendByte((Address & 0xFFFFFF) >> 16); //Send 8 Upper Bits of Address
SPI_Flash_SendByte((Address & 0xFFFF) >> 8); //Send Next 8 Bits
SPI_Flash_SendByte(Address & 0xFF); //Send Last 8 Bits
FLASH_CS_PIN = 1; //Disable Flash Chip
SPI_Flash_WRDI(); //Disable Write Ability
}