Send a command to the flash chip, pass TRUE for isWrite when its a write command
| 171 | |
| 172 | /// Send a command to the flash chip, pass TRUE for isWrite when its a write command |
| 173 | void SPIFlash::command(uint8_t cmd, boolean isWrite){ |
| 174 | #if defined(__AVR_ATmega32U4__) // Arduino Leonardo, MoteinoLeo |
| 175 | DDRB |= B00000001; // Make sure the SS pin (PB0 - used by RFM12B on MoteinoLeo R1) is set as output HIGH! |
| 176 | PORTB |= B00000001; |
| 177 | #endif |
| 178 | if (isWrite) |
| 179 | { |
| 180 | command(SPIFLASH_WRITEENABLE); // Write Enable |
| 181 | unselect(); |
| 182 | } |
| 183 | //wait for any write/erase to complete |
| 184 | // a time limit cannot really be added here without it being a very large safe limit |
| 185 | // that is because some chips can take several seconds to carry out a chip erase or other similar multi block or entire-chip operations |
| 186 | // 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 |
| 187 | // 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 |
| 188 | if (cmd != SPIFLASH_WAKE) while(busy()); |
| 189 | select(); |
| 190 | SPI.transfer(cmd); |
| 191 | } |
| 192 | |
| 193 | /// check if the chip is busy erasing/writing |
| 194 | boolean SPIFlash::busy() |
nothing calls this directly
no outgoing calls
no test coverage detected