From a349130cc33231442dc3fd2fd13e57dae3d9bb1b Mon Sep 17 00:00:00 2001 From: LowPowerLab Date: Thu, 8 Jan 2015 20:44:12 -0500 Subject: [PATCH] Add busy() while() explanation --- SPIFlash.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/SPIFlash.cpp b/SPIFlash.cpp index 2817242..03d6a1a 100644 --- a/SPIFlash.cpp +++ b/SPIFlash.cpp @@ -139,7 +139,12 @@ void SPIFlash::command(byte cmd, boolean isWrite){ command(SPIFLASH_WRITEENABLE); // Write Enable unselect(); } - while(busy()); //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 + while(busy()); select(); SPI.transfer(cmd); }