miguelbalboa / rfid

Arduino RFID Library for MFRC522
The Unlicense
2.74k stars 1.43k forks source link

SPI default clock rate too slow (and in contradiction of the Arduino API standard) on RP2040 #563

Closed WestfW closed 3 years ago

WestfW commented 3 years ago

The RP2040 implementation of SPI has (in the relevant SPI.h):

class MbedSPI : public SPIClass
{
   :
private:
    SPISettings settings = SPISettings(0, MSBFIRST, SPI_MODE0);
   : 

where "0" is the bitrate. Presumably, at some point this is converted to the default SPI clock rate for mBed, buried deep inside the mBed code, and it becomes about 1MHz. However, I think it should be just:

    SPISettings settings = SPISettings();

or perhaps

   SPISettings = DEFAULT_SPI_SETTINGS;

(both of which come from API/HardwareSPI.h, and defined a default bitrate of 4MHz.)

With the current code, the default SPI bitrate for RP2040 based boards is one quarter of the speed that it is on an AVR.

A possible workaround, and to get higher speeds, is for uses to provide their own SPI settings:

SPISettings mySPIsettings = SPISettings(10000000, MSBFIRST, SPI_MODE0);  //10MHz
SPI.beginTransaction(mySPIsettings);
WestfW commented 3 years ago

oops! this doesn't belong here!