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

Method writeFloat

src/SPIFlash.cpp:966–997  ·  view source on GitHub ↗

Writes a float 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 float 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/e

Source from the content-addressed store, hash-verified

964// WARNING: You can only write to previously erased memory locations (see datasheet).
965// Use the eraseSector()/eraseBlock32K/eraseBlock64K commands to first clear memory (write 0xFFs)
966bool SPIFlash::writeFloat(uint32_t _addr, float data, bool errorCheck) {
967 //return _write(_addr, data, sizeof(data), errorCheck, _FLOAT_);
968 #ifdef RUNDIAGNOSTIC
969 _spifuncruntime = micros();
970 #endif
971 if(!_prep(PAGEPROG, _addr, sizeof(data))) {
972 return false;
973 }
974
975 union {
976 float Float;
977 uint8_t byte[sizeof(float)];
978 } dataOut;
979 dataOut.Float = data;
980
981 _beginSPI(PAGEPROG);
982 for (uint8_t i = 0; i < sizeof(data); i++) {
983 _nextByte(WRITE, dataOut.byte[i]);
984 }
985 CHIP_DESELECT
986
987 if (!errorCheck) {
988 _endSPI();
989 #ifdef RUNDIAGNOSTIC
990 _spifuncruntime = micros() - _spifuncruntime;
991 #endif
992 return true;
993 }
994 else {
995 if (!_notBusy()) {
996 return false;
997 }
998 union {
999 uint8_t byte[4];
1000 float Float;

Callers

nothing calls this directly

Calls 1

ifFunction · 0.70

Tested by

no test coverage detected