/************************************************************************ * Function: void SST25SectorErase(DWORD address) * * Overview: this function erases a 4Kb sector * * Input: address within sector to be erased * * Output: none * ************************************************************************/ void SST25SectorErase(DWORD address) { SST25WriteEnable(); while(!SPILock(spiInitData.channel)) ; DRV_SPI_Initialize(spiInitData.channel, (DRV_SPI_INIT_DATA *)&spiInitData); SST25CSLow(); SPIPut(spiInitData.channel, SST25_CMD_SER); SPIGet(spiInitData.channel); SPIPut(spiInitData.channel, ((DWORD_VAL) address).v[2]); SPIGet(spiInitData.channel); SPIPut(spiInitData.channel, ((DWORD_VAL) address).v[1]); SPIGet(spiInitData.channel); SPIPut(spiInitData.channel, ((DWORD_VAL) address).v[0]); SPIGet(spiInitData.channel); SST25CSHigh(); SPIUnLock(spiInitData.channel); // Wait for write end while(SST25IsWriteBusy()); }
/************************************************************************ * Function: void SST25WriteByte(BYTE data, DWORD address) * * Overview: this function writes a byte to the address specified * * Input: data to be written and address * * Output: none * ************************************************************************/ void SST25WriteByte(BYTE data, DWORD address) { // SST25SectorErase(address); //DelayMs(100); SST25WriteEnable(); SST25SSLow(); SPIPut(SST25_CMD_WRITE); SPIGet(); SPIPut(((DWORD_VAL) address).v[2]); SPIGet(); SPIPut(((DWORD_VAL) address).v[1]); SPIGet(); SPIPut(((DWORD_VAL) address).v[0]); SPIGet(); SPIPut(data); SPIGet(); SST25SSHigh(); // Wait for write end while(SST25IsWriteBusy()); }
/************************************************************************ * Function: void SST25SectorErase(DWORD address) * * Overview: this function erases a 4Kb sector * * Input: address within sector to be erased * * Output: none * ************************************************************************/ void SST25SectorErase(uint32_t address) { SST25WriteEnable(); // while(!SPILock(spiInitData.spiId)); SST25CSLow(); SPIPut(spiInitData.spiId, SST25_CMD_SER); PLIB_SPI_BufferRead(spiInitData.spiId); SPIPut(spiInitData.spiId, address>>16); PLIB_SPI_BufferRead(spiInitData.spiId); SPIPut(spiInitData.spiId, address>>8); PLIB_SPI_BufferRead(spiInitData.spiId); SPIPut(spiInitData.spiId, address); PLIB_SPI_BufferRead(spiInitData.spiId); SST25CSHigh(); // SPIUnLock(spiInitData.spiId); // Wait for write end while(SST25IsWriteBusy()); }
/************************************************************************ * Function: void SST25WriteByte(BYTE data, DWORD address) * * Overview: this function writes a byte to the address specified * * Input: data to be written and address * * Output: none * ************************************************************************/ void SST25WriteByte(uint8_t data, uint32_t address) { SST25WriteEnable(); SST25CSLow(); SPIPut(spiInitData.spiId, SST25_CMD_WRITE); PLIB_SPI_BufferRead(spiInitData.spiId); SPIPut(spiInitData.spiId, address>>16); PLIB_SPI_BufferRead(spiInitData.spiId); SPIPut(spiInitData.spiId, address>>8); PLIB_SPI_BufferRead(spiInitData.spiId); SPIPut(spiInitData.spiId, address); PLIB_SPI_BufferRead(spiInitData.spiId); SPIPut(spiInitData.spiId, data); PLIB_SPI_BufferRead(spiInitData.spiId); SST25CSHigh(); // Wait for write end while(SST25IsWriteBusy()); }
/************************************************************************ * Function: void SST25ChipErase(void) * * Overview: chip erase * * Input: none * ************************************************************************/ void SST25ChipErase(void) { SST25WriteEnable(); SST25SSLow(); SPIPut(SST25_CMD_ERASE); SPIGet(); SST25SSHigh(); // Wait for write end while(SST25IsWriteBusy()); }
/************************************************************************ * Function: void SST25SectorErase(DWORD address) * * Overview: this function erases a 4Kb sector * * Input: address within sector to be erased * * Output: none * ************************************************************************/ void SST25SectorErase(DWORD address) { SST25WriteEnable(); SST25SSLow(); SPIPut(SST25_CMD_SER); SPIGet(); SPIPut(((DWORD_VAL) address).v[2]); SPIGet(); SPIPut(((DWORD_VAL) address).v[1]); SPIGet(); SPIPut(((DWORD_VAL) address).v[0]); SPIGet(); SST25SSHigh(); // Wait for write end DelayMs(100); while(SST25IsWriteBusy()); }
/************************************************************************ * Function: void SST25ChipErase(void) * * Overview: chip erase * * Input: none * ************************************************************************/ void SST25ChipErase(void) { #if defined(USE_M25P80) BYTE status; #endif #if defined(USE_SST25VF016) SST25WriteEnable(); #endif while(!SPILock(spiInitData.channel)) ; DRV_SPI_Initialize(spiInitData.channel, (DRV_SPI_INIT_DATA *)&spiInitData); SST25CSLow(); #if defined(USE_M25P80) // send write enable command SPIPut(spiInitData.channel, SST25_CMD_EWSR); SPIGet(spiInitData.channel); SST25CSHigh(); Nop(); SST25CSLow(); // verify if the WEL bit is set high while(1) { SPIPut(spiInitData.channel, SST25_CMD_RDSR); SPIGet(spiInitData.channel); status = 0xFF; while((status & SST25_STATUS_MASK) > 0) { SPIPut(spiInitData.channel, 0); status = SPIGet(spiInitData.channel); } if ((status & SST25_WEL_STATUS) == SST25_WEL_STATUS) break; } SST25CSHigh(); #endif SST25CSLow(); SPIPut(spiInitData.channel, SST25_CMD_ERASE); SPIGet(spiInitData.channel); SST25CSHigh(); #if defined (USE_M25P80) // wait for BULK ERASE to be done SST25CSLow(); SPIPut(spiInitData.channel, SST25_CMD_RDSR); SPIGet(spiInitData.channel); while(1) { SPIPut(spiInitData.channel, 0); status = (SPIGet(spiInitData.channel)& SST25_WIP_STATUS); if ((status & SST25_WIP_STATUS) == 0) break; } SST25CSHigh(); #endif SPIUnLock(spiInitData.channel); // Wait for write end while(SST25IsWriteBusy()); }
/************************************************************************ * Function: void SST25ChipErase(void) * * Overview: chip erase * * Input: none * ************************************************************************/ void SST25ChipErase(void) { #if defined(USE_M25P80) uint8_t status; #endif #if defined(USE_SST25VF016) SST25WriteEnable(); #endif // while(!SPILock(spiInitData.spiId)); SST25CSLow(); #if defined(USE_M25P80) // send write enable command SPIPut(spiInitData.spiId, SST25_CMD_EWSR); SPIGet(spiInitData.spiId); SST25CSHigh(); Nop(); SST25CSLow(); // verify if the WEL bit is set high while(1) { SPIPut(spiInitData.spiId, SST25_CMD_RDSR); SPIGet(spiInitData.spiId); status = 0xFF; while((status & SST25_STATUS_MASK) > 0) { SPIPut(spiInitData.spiId, 0); status = SPIGet(spiInitData.spiId); } if ((status & SST25_WEL_STATUS) == SST25_WEL_STATUS) break; } SST25CSHigh(); #endif SST25CSLow(); SPIPut(spiInitData.spiId, SST25_CMD_ERASE); PLIB_SPI_BufferRead(spiInitData.spiId); SST25CSHigh(); #if defined (USE_M25P80) // wait for BULK ERASE to be done SST25CSLow(); SPIPut(spiInitData.spiId, SST25_CMD_RDSR); SPIGet(spiInitData.spiId); while(1) { SPIPut(spiInitData.spiId, 0); status = (SPIGet(spiInitData.spiId)& SST25_WIP_STATUS); if ((status & SST25_WIP_STATUS) == 0) break; } SST25CSHigh(); #endif // SPIUnLock(spiInitData.spiId); // Wait for write end while(SST25IsWriteBusy()); }