Sets the SPI clock speed. The value can be specified as a direct value, or as as a value plus a multiplier.
// SYNTAX SPI.setClockSpeed(value, scale); SPI.setClockSpeed(frequency); // EXAMPLE // Set the clock speed as close to 15MHz (but not over) SPI.setClockSpeed(15, MHZ); SPI.setClockSpeed(15000000);
The clock speed cannot be set to any arbitrary value, but is set internally by using a
SPI.setClockDivider()) that gives the highest clock speed not greater
than the one specified.
This method can make writing portable code easier, since it specifies the clock speed absolutely, giving comparable results across devices. In contrast, specifying the clock speed using dividers is typically not portable since is dependent upon the system clock speed.
Note that you must use the same
SPI object as used with
SPI.begin() so if you used
SPI1.begin() also use
Gen 3 devices (Argon, Boron, B Series SoM, and Tracker SoM) support SPI speeds up to 32 MHz on SPI and 8 MHz on SPI1.