MCPcopy Create free account
hub / github.com/Marzogh/SPIMemory / writeByte

Method writeByte

src/SPIFram.cpp:334–373  ·  view source on GitHub ↗

Writes a byte of data to a specific location in a page. Takes three arguments - 1. _addr --> Any address - from 0 to capacity 2. data --> One byte to be written to a particular location on a page 3. errorCheck --> Turned on by default. Checks for writing errors WARNING: You can only write to previously erased memory locations (see datasheet). Use the eraseSector()/eraseBlock32K/eraseBlock64K comma

Source from the content-addressed store, hash-verified

332// WARNING: You can only write to previously erased memory locations (see datasheet).
333// Use the eraseSector()/eraseBlock32K/eraseBlock64K commands to first clear memory (write 0xFFs)
334bool SPIFram::writeByte(uint32_t _addr, uint8_t data, bool errorCheck) {
335 //return _write(_addr, data, sizeof(data), errorCheck, _BYTE_);
336 #ifdef RUNDIAGNOSTIC
337 _spifuncruntime = micros();
338 #endif
339 if(_isChipPoweredDown() || !_addressCheck(_addr, sizeof(data)) || !_notPrevWritten(_addr, sizeof(data)) || !_writeEnable()) {
340 return false;
341 }
342
343 _beginSPI(PAGEPROG);
344 _nextByte(WRITE, data);
345 CHIP_DESELECT
346
347 if (!errorCheck) {
348 _endSPI();
349 #ifdef RUNDIAGNOSTIC
350 _spifuncruntime = micros() - _spifuncruntime;
351 #endif
352 return true;
353 }
354 else {
355 _currentAddress = _addr;
356 CHIP_SELECT
357 _nextByte(WRITE, READDATA);
358 _transferAddress();
359 if (data != _nextByte(READ)) {
360 _endSPI();
361 #ifdef RUNDIAGNOSTIC
362 _spifuncruntime = micros() - _spifuncruntime;
363 #endif
364 return false;
365 }
366 else {
367 _endSPI();
368 #ifdef RUNDIAGNOSTIC
369 _spifuncruntime = micros() - _spifuncruntime;
370 #endif
371 return true;
372 }
373 }
374 return true;
375}
376

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected