Skip to content
Marzogh edited this page Jun 2, 2019 · 6 revisions

Read functions

Note on fastRead

  • All read commands take a last boolean argument 'fastRead'. This argument defaults to FALSE, and does not need to be specified when calling a function.

    For example:

    //Calling
    
    flash.readByte(addressToReadFrom);
    
    //or
    
    flash.readByte(addressToReadFrom, FALSE);
    

    yields the same results.

  • However, when this argument is set to ENFASTREAD, it carries out the Fast Read instruction so data can be read at up to the memory's maximum frequency.

    //Calling
    
    flash.readByteArray(addressToReadFrom, bufferToReadTo, bufferSize, ENFASTREAD);
    
    //instead of
    
    flash.readByteArray(addressToReadFrom, bufferToReadTo, bufferSize);
    

    will result in faster read speeds for very large data arrays.

This is useful only when reading very large amounts of data from the flash memory.

If used for small arrays or individual variables will slow down the read function.


Data type-independent functions

readAnything(address, value, fastRead)

Reads any type of variable / struct (any sized value) from a specific address and returns it. Takes the address where the data was previously written and the variable / struct to write the data back to, as arguments.

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


Data type-specific functions

readByte(address, fastRead)

Reads a byte (unsigned 8 bit value) from a specific address and returns it. Takes the address where the data was previously written as an argument.

readChar(address, fastRead)

Reads a char (signed 8 bit value) from a specific address and returns it. Takes the address where the data was previously written as an argument.

readWord(address, fastRead)

Reads a word (unsigned 16 bit value) from a specific address and returns it. Takes the address where the data was previously written as an argument.

readShort(address, fastRead)

Reads a short (signed 16 bit value) from a specific address and returns it. Takes the address where the data was previously written as an argument.

readULong(address, fastRead)

Reads an unsigned long (unsigned 32 bit value) from a specific address and returns it. Takes the address where the data was previously written as an argument.

readLong(address, fastRead)

Reads a long (signed 32 bit value) from a specific address and returns it. Takes the address where the data was previously written as an argument.

readFloat(address, fastRead)

Reads a float (decimal value) from a specific address and returns it. Takes the address where the data was previously written as an argument.

readStr(address, outputStr, fastRead)

Reads a string (String Object) from a specific address to an outputStr variable. Takes the address where the data was previously written and a String object to save the data to, as arguments.

readByteArray(address, *data_buffer, bufferSize, fastRead)

Reads an array of bytes (unsigned 8-bit values) starting from a specific address. Takes the address and a data_buffer - i.e. an array of bytes to be read from 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.

readCharArray(address, *data_buffer, bufferSize, fastRead)

Reads an array of chars (signed 8-bit values) starting from a specific address. Takes the address and a data_buffer - i.e. an array of chars to be read from 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.