Single variable write functions¶
These functions are designed to write a single variable - of a specific data type - to the flash memory. Each supported data type has a function specific to it - as listed below:
-
bool
writeByte(uint32_t _addr, uint8_t data, bool errorCheck = true)¶
- Writes an unsigned 8 bit integer - a
byte- to the address specified.
-
bool
writeChar(uint32_t _addr, int8_t data, bool errorCheck = true)¶
- Writes a signed 8 bit integer - a
char- to the address specified.
-
bool
writeShort(uint32_t _addr, int16_t data, bool errorCheck = true)¶
- Writes a signed 16 bit integer - a
short- to the address specified.
-
bool
writeWord(uint32_t _addr, uint16_t data, bool errorCheck = true)¶
- Writes an unsigned 16 bit integer - a
word- to the address specified.
-
bool
writeLong(uint32_t _addr, int32_t data, bool errorCheck = true)¶
- Writes a signed 32 bit integer - a
long- to the address specified.
-
bool
writeULong(uint32_t _addr, uint32_t data, bool errorCheck = true)¶
- Writes an unsigned 32 bit integer - an
unsigned long- to the address specified.
-
bool
writeFloat(uint32_t _addr, float data, bool errorCheck = true)¶
- Writes a
floatto the address specified.
-
bool
writeStr(uint32_t _addr, String &data, bool errorCheck = true)¶
- Writes a
Stringto the address specified.
Parameters Mandatory & Optional¶
-
uint32_t
_addr
Address in memory where the data is to be written to. Mandatory
-
size_t
data
Data variable to write to the flash memory. Mandatory
-
bool
errorCheck
Refer to Advanced use Optional
What they do¶
Write the data (of the datatype and size specified by the user) to the address provided
Returns boolean¶
Returns TRUE if data written successfully, else returns FALSE
Example code:¶
#include <SPIMemory.h>
SPIFlash flash;
uint32_t _address;
// This data type should be changed depending on the type of data being write to the flash memory
String dataOut = "This is a test String!";
void setup() {
flash.begin();
_address = flash.getAddress(sizeof(dataIn));
Serial.print("Address = ");
Serial.println(_address);
Serial.print("Data write ");
// This function should be changed depending on the type of data being written to the flash memory
if (flash.writeStr(_address, dataOut)) {
Serial.println("successful");
}
else {
Serial.println("failed");
}
}
void loop() {
}