Merge pull request #28 from JasonC0x0D/update_comment

Updated Comments about sleep()
This commit is contained in:
Felix Rusu 2021-06-08 08:14:34 -04:00 committed by GitHub
commit e80a582218
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 6 deletions

View File

@ -41,6 +41,13 @@ uint8_t SPIFlash::UNIQUEID[8];
/// See http://en.wikipedia.org/wiki/Flash_memory
/// The smallest range that can be erased is a sector (4K, 32K, 64K); there is also a chip erase command
/// IMPORTANT: When flash chip is powered down, aka sleeping, the only command it will respond to is
/// Release Power-down / Device ID (ABh), per section 8.2.19 of the W25X40CL datasheet.
/// This means after using the sleep() function of this library, wake() must be the first
/// function called. If other commands are used, the flash chip will ignore the commands.
/// The risk is that the code can hang if there is noise/static on the MISO line,
/// specifically noise/static that would evaluate to HIGH or 1.
/// Constructor. JedecID is optional but recommended, since this will ensure that the device is present and has a valid response
/// get this from the datasheet of your flash chip
/// Example for Atmel-Adesto 4Mbit AT25DF041A: 0x1F44 (page 27: http://www.adestotech.com/sites/default/files/datasheets/doc3668.pdf)
@ -180,11 +187,14 @@ void SPIFlash::command(uint8_t cmd, boolean isWrite){
command(SPIFLASH_WRITEENABLE); // Write Enable
unselect();
}
//wait for any write/erase to complete
// wait for any write/erase to complete
// a time limit cannot really be added here without it being a very large safe limit
// that is because some chips can take several seconds to carry out a chip erase or other similar multi block or entire-chip operations
// a recommended alternative to such situations where chip can be or not be present is to add a 10k or similar weak pulldown on the
// open drain MISO input which can read noise/static and hence return a non 0 status byte, causing the while() to hang when a flash chip is not present
//
// Note: If the MISO line is high, busy() will return true.
// This can be a problem and cause the code to hang when there is noise/static on MISO data line when:
// 1) There is no flash chip connected
// 2) The flash chip connected is powered down, aka sleeping.
if (cmd != SPIFLASH_WAKE) while(busy());
select();
SPI.transfer(cmd);