Skip to content

Library instantiation functions

Marzogh edited this page Jun 1, 2019 · 4 revisions

Library instantiation functions

These functions prime the library for further use and should be called as required.

begin(_chipSize)

  • Must be called at the start in void setup(). This function detects the type of chip being used and sets parameters accordingly. An optional _chipSize parameter can be declared as an argument with this function. (>v2.6.0)

  • This function is essential to the functioning of the library and must be called before any other calls are made to the library.

  • If this function is not called the library throws an error - 0x01 a.k.a CALLBEGIN. (Refer to Diagnostics & Error reporting for further details)

setClock(clockSpeed)

  • This is an optional function and is used to set the SPI clock speed for all further comms using the library.

  • Starting v3.4.0, if required, must be called right before begin().

  • If SPI_HAS_TRANSACTION is defined, this function takes a 32-bit number (in Hertz) as replacement for the default maximum clock speed (104MHz for Winbond NOR flash) thereby initiating future SPI transactions with the user-defined clock speed.

  • If SPI_HAS_TRANSACTION is not defined, it takes SPI_CLOCK_DIVx. In either case sets the clock speed for SPI.

    Use with care.

    For example:

    A. If the flash memory chip requires the SPI clock to run at 20MHz, and the µC has SPI Transactions support, the following call is made to this function:

    void setup() {
      flash.setClock(20000000);
      flash.begin();
      ...
    }
    

    B. If the flash memory chip requires the SPI clock to run at ¼ of the SPI clock of the µC, and the µC does not have SPI Transactions support, the following call is made to this function:

    void setup() {
      flash.setClock(SPI_CLOCK_DIV4);
      flash.begin();
      ...
    }