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

Method writeShort

src/SPIFlash.cpp:792–817  ·  view source on GitHub ↗

Writes a signed int as two bytes starting from a specific location in a page Takes three arguments - 1. _addr --> Any address - from 0 to capacity 2. data --> One short 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()/eraseBlock3

Source from the content-addressed store, hash-verified

790// WARNING: You can only write to previously erased memory locations (see datasheet).
791// Use the eraseSector()/eraseBlock32K/eraseBlock64K commands to first clear memory (write 0xFFs)
792bool SPIFlash::writeShort(uint32_t _addr, int16_t data, bool errorCheck) {
793 //return _write(_addr, data, sizeof(data), errorCheck, _SHORT_);
794 #ifdef RUNDIAGNOSTIC
795 _spifuncruntime = micros();
796 #endif
797 if(!_prep(PAGEPROG, _addr, sizeof(data))) {
798 return false;
799 }
800
801 _beginSPI(PAGEPROG);
802 for (uint8_t i = 0; i < sizeof(data); i++) {
803 _nextByte(WRITE, data >> (8*i));
804 }
805 CHIP_DESELECT
806
807 if (!errorCheck) {
808 _endSPI();
809 #ifdef RUNDIAGNOSTIC
810 _spifuncruntime = micros() - _spifuncruntime;
811 #endif
812 return true;
813 }
814 else {
815 if (!_notBusy()) {
816 return false;
817 }
818 union {
819 uint8_t byte[2];
820 int16_t short_;

Callers

nothing calls this directly

Calls 1

ifFunction · 0.70

Tested by

no test coverage detected