Skip to content
Matt Cochrane edited this page Apr 27, 2018 · 9 revisions

Write functions

Note on errorCheck

  • All write commands take a last boolean argument 'errorCheck'. This argument defaults to TRUE, and does not need to be specified when calling a function.

    For example:

    //Calling
    
    flash.writeByte(addressToWriteTo, dataToWrite);
    
    //or
    
    flash.writeByte(addressToWriteTo, dataToWrite, TRUE);
    

    yields the same results.

  • However, when this argument is set to NOERRCHK, it does not check to see that the data has been properly written. This will speed up the writing process enormously at the risk of data corruption not being caught

    //Calling
    
    flash.writeByteArray(addressToWriteTo, bufferToWriteFrom, bufferSize, NOERRCHK);
    
    //instead of
    
    flash.writeByteArray(addressToWriteTo, bufferToWriteFrom, bufferSize);
    

    will result in faster write speeds for the data array, but, any errors that occur will not be caught by the library.

This is useful only when speed is more important than catching erroneous writes.


Data type-independent functions

writeAnything(address, value, errorCheck)

Writes any type of variable / struct (any sized value) to a specific address. Takes the address where the data is to be written to and the variable / struct to write the data back to, as arguments.

Note: This function can be used to replace any of the write functions below (except writeByteArray() and writeCharArray()). However, if used for anything other than structs, this function runs slower than the data type-specific ones below.


Data type-specific functions

writeByte(address, data, errorCheck)

Writes a byte (unsigned 8 bit value) to a specific address. Takes the address where the data is to be written to, as an argument. It returns a boolean value to indicate a successful/unsuccessful write.

writeChar(address, data, errorCheck)

Writes a char (signed 8 bit value) to a specific address. Takes the address where the data is to be written to, as an argument. It returns a boolean value to indicate a successful/unsuccessful write.

writeWord(address, data, errorCheck)

Writes a word (unsigned 16 bit value) to a specific address. Takes the address where the data is to be written to, as an argument. It returns a boolean value to indicate a successful/unsuccessful write.

writeShort(address, data, errorCheck)

Writes a short (signed 16 bit value) to a specific address. Takes the address where the data is to be written to, as an argument. It returns a boolean value to indicate a successful/unsuccessful write.

writeULong(address, data, errorCheck)

Writes an unsigned long (unsigned 32 bit value) to a specific address. Takes the address where the data is to be written to, as an argument. It returns a boolean value to indicate a successful/unsuccessful write.

writeLong(address, data, errorCheck)

Writes a long (signed 32 bit value) to a specific address. Takes the address where the data is to be written to, as an argument. It returns a boolean value to indicate a successful/unsuccessful write.

writeFloat(address, data, errorCheck)

Writes a float (decimal value) to a specific address. Takes the address where the data is to be written to, as an argument. It returns a boolean value to indicate a successful/unsuccessful write.

writeStr(address, *data, errorCheck)

Writes a string (String Object) to a specific address to an outputStr variable. Takes the address where the data is to be written to, and a String object to save the data to, as arguments. It returns a boolean value to indicate a successful/unsuccessful write.

writeByteArray(address, *data_buffer, bufferSize, errorCheck)

Writes an array of bytes (unsigned 8-bit values) starting to a specific address. Takes the address and a data_buffer - i.e. an array of bytes to be write to the flash memory - and size of the array as arguments. uint8_t data_buffer[n]; The data buffer must be an array of n bytes. 'n' is limited by the amount of free RAM available on the microcontroller. It returns a boolean value to indicate a successful/unsuccessful write.

writeCharArray(address, *data_buffer, bufferSize, errorCheck)

Writes an array of chars (signed 8-bit values) starting to a specific address. Takes the address and a data_buffer - i.e. an array of chars to be write to the flash memory - and size of the array as arguments. char data_buffer[n]; The data buffer must be an array of n chars. 'n' is limited by the amount of free RAM available on the Arduino board. It returns a boolean value to indicate a successful/unsuccessful write.