Writes a signed long as four bytes starting from a specific location in a page Takes three arguments - 1. _addr --> Any address - from 0 to capacity 2. data --> One signed long 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()/era
| 758 | // WARNING: You can only write to previously erased memory locations (see datasheet). |
| 759 | // Use the eraseSector()/eraseBlock32K/eraseBlock64K commands to first clear memory (write 0xFFs) |
| 760 | bool SPIFram::writeLong(uint32_t _addr, int32_t data, bool errorCheck) { |
| 761 | //return _write(_addr, data, sizeof(data), errorCheck, _LONG_); |
| 762 | #ifdef RUNDIAGNOSTIC |
| 763 | _spifuncruntime = micros(); |
| 764 | #endif |
| 765 | if(_isChipPoweredDown() || !_addressCheck(_addr, sizeof(data)) || !_notPrevWritten(_addr, sizeof(data)) || !_writeEnable()) { |
| 766 | return false; |
| 767 | } |
| 768 | |
| 769 | _beginSPI(PAGEPROG); |
| 770 | for (uint8_t i = 0; i < sizeof(data); i++) { |
| 771 | _nextByte(WRITE, data >> (8*i)); |
| 772 | } |
| 773 | CHIP_DESELECT |
| 774 | |
| 775 | if (!errorCheck) { |
| 776 | _endSPI(); |
| 777 | #ifdef RUNDIAGNOSTIC |
| 778 | _spifuncruntime = micros() - _spifuncruntime; |
| 779 | #endif |
| 780 | return true; |
| 781 | } |
| 782 | else { |
| 783 | union { |
| 784 | uint8_t byte[4]; |
| 785 | int32_t Long; |
| 786 | } dataIn; |
| 787 | _currentAddress = _addr; |
| 788 | CHIP_SELECT |
| 789 | _nextByte(WRITE, READDATA); |
| 790 | _transferAddress(); |
| 791 | for (uint8_t i = 0; i < sizeof(data); i++) { |
| 792 | dataIn.byte[i] = _nextByte(READ); |
| 793 | } |
| 794 | _endSPI(); |
| 795 | if (dataIn.Long != data) { |
| 796 | #ifdef RUNDIAGNOSTIC |
| 797 | _spifuncruntime = micros() - _spifuncruntime; |
| 798 | #endif |
| 799 | return false; |
| 800 | } |
| 801 | #ifdef RUNDIAGNOSTIC |
| 802 | _spifuncruntime = micros() - _spifuncruntime; |
| 803 | #endif |
| 804 | } |
| 805 | return true; |
| 806 | } |
| 807 |
nothing calls this directly
no outgoing calls
no test coverage detected