begin¶
Signatures¶
bool SPIFlash::begin(uint32_t flashChipSize = 0)bool SPIFram::begin(uint32_t flashChipSize = 0)
What It Is For¶
Initialize SPI memory communication, detect chip identity, load capacity/page behavior, and prepare the object for read/write operations.
Parameters¶
flashChipSize: Optional explicit size override for unsupported or custom chips. Leave0for automatic detection.
Behavior Details¶
begin() must be called once in setup() before any data I/O. It configures communication, verifies chip support, and caches capacity/ID information used by every later call.
Return Semantics¶
Returns true on successful initialization and chip identification. Returns false if comms/ID/support checks fail.
Failure Behavior¶
Failure usually indicates wiring issues, wrong CS pin, unsupported chip, incorrect voltage levels, or SPI bus mismatch. Check error(VERBOSE) immediately.
Common Mistakes¶
- Calling memory I/O before
begin()has succeeded. - Passing a custom
flashChipSizethat does not match real hardware. - Ignoring a
falsereturn and continuing instead of checkingerror(VERBOSE).
Choosing Between Similar APIs¶
- Use
begin(0)for normal auto-detection. - Use non-zero
flashChipSizeonly for unsupported/custom chips where auto-detect is inadequate. - If
begin()is unstable, fix wiring/clock before trying advanced APIs.
Example¶
SPIFlash flash(10);
void setup() {
Serial.begin(115200);
if (!flash.begin()) {
flash.error(VERBOSE);
while (1) {}
}
}