Browse Source

begin() returns false when chip not detected, fixes #53

main
PaulStoffregen 6 years ago
parent
commit
754e1d025c
4 changed files with 17 additions and 3 deletions
  1. +3
    -0
      SerialFlashChip.cpp
  2. +7
    -1
      examples/CopyFromSerial/CopyFromSerial.ino
  3. +6
    -1
      examples/EraseEverything/EraseEverything.ino
  4. +1
    -1
      examples/RawHardwareTest/RawHardwareTest.ino

+ 3
- 0
SerialFlashChip.cpp View File

pinMode(pin, OUTPUT); pinMode(pin, OUTPUT);
CSRELEASE(); CSRELEASE();
readID(id); readID(id);
if ((id[0]==0 && id[1]==0 && id[2]==0) || (id[0]==255 && id[1]==255 && id[2]==255)) {
return false;
}
f = 0; f = 0;
size = capacity(id); size = capacity(id);
if (size > 16777216) { if (size > 16777216) {

+ 7
- 1
examples/CopyFromSerial/CopyFromSerial.ino View File

//SPI.setMOSI(MOSI); // uncomment these if using the alternate pins //SPI.setMOSI(MOSI); // uncomment these if using the alternate pins
//SPI.setMISO(MISO); //SPI.setMISO(MISO);
//SPI.setSCK(SCK); //SPI.setSCK(SCK);
SerialFlash.begin(CSPIN);
if (!SerialFlash.begin(CSPIN)) {
while (1) {
Serial.println("Unable to access SPI Flash chip");
delay(1000);
}
}



//We start by formatting the flash... //We start by formatting the flash...
uint8_t id[5]; uint8_t id[5];

+ 6
- 1
examples/EraseEverything/EraseEverything.ino View File

while (!Serial && (millis() - startMillis < 10000)) ; while (!Serial && (millis() - startMillis < 10000)) ;
delay(100); delay(100);


SerialFlash.begin(FlashChipSelect);
if (!SerialFlash.begin(FlashChipSelect)) {
while (1) {
Serial.println("Unable to access SPI Flash chip");
delay(1000);
}
}
unsigned char id[5]; unsigned char id[5];
SerialFlash.readID(id); SerialFlash.readID(id);
unsigned long size = SerialFlash.capacity(id); unsigned long size = SerialFlash.capacity(id);

+ 1
- 1
examples/RawHardwareTest/RawHardwareTest.ino View File

delay(100); delay(100);


Serial.println("Raw SerialFlash Hardware Test"); Serial.println("Raw SerialFlash Hardware Test");
SerialFlash.begin(FlashChipSelect);
SerialFlash.begin(FlashChipSelect); // proceed even if begin() fails


if (test()) { if (test()) {
Serial.println(); Serial.println();

Loading…
Cancel
Save