Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
add macro SPI_32MHZ_INTERFACE to variant to select SPI or SPI1 to use…
… 32mhz SPIM3

default to SPI or 0
  • Loading branch information
hathach committed Feb 18, 2020
commit 050129e00312febfdec94be3162aa5d946002904
25 changes: 21 additions & 4 deletions libraries/SPI/SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,30 @@ void SPIClass::detachInterrupt() {
// Should be disableInterrupt()
}

#if SPI_INTERFACES_COUNT > 0
// default to 0
#ifndef SPI_32MHZ_INTERFACE
#define SPI_32MHZ_INTERFACE 0
#endif

#if SPI_32MHZ_INTERFACE == 0
#define _SPI_DEV NRF_SPIM3 // 32 Mhz
#define _SPI1_DEV NRF_SPIM2

#elif SPI_32MHZ_INTERFACE == 1
#define _SPI_DEV NRF_SPIM2
#define _SPI1_DEV NRF_SPIM3 // 32 Mhz

#else
#error "not supported yet"
#endif

#if SPI_INTERFACES_COUNT >= 1
// use SPIM3 for highspeed 32Mhz
SPIClass SPI(NRF_SPIM3, PIN_SPI_MISO, PIN_SPI_SCK, PIN_SPI_MOSI);
SPIClass SPI(_SPI_DEV, PIN_SPI_MISO, PIN_SPI_SCK, PIN_SPI_MOSI);
#endif

#if SPI_INTERFACES_COUNT > 1
SPIClass SPI1(NRF_SPIM2, PIN_SPI1_MISO, PIN_SPI1_SCK, PIN_SPI1_MOSI);
#if SPI_INTERFACES_COUNT >= 2
SPIClass SPI1(_SPI1_DEV, PIN_SPI1_MISO, PIN_SPI1_SCK, PIN_SPI1_MOSI);
#endif

#endif // NRF52840_XXAA
8 changes: 7 additions & 1 deletion variants/clue_nrf52840/variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ static const uint8_t A7 = PIN_A7 ;
*/
#define SPI_INTERFACES_COUNT 2

// nRF52840 has only one SPIM3 runing at highspeed 32Mhz
// This assign SPIM3 to either: SPI (0), SPI1 (1).
// If not defined, default to 0 or SPI.
#define SPI_32MHZ_INTERFACE 1

// SPI
#define PIN_SPI_MISO (14)
#define PIN_SPI_MOSI (15)
#define PIN_SPI_SCK (13)
Expand All @@ -102,7 +108,7 @@ static const uint8_t MOSI = PIN_SPI_MOSI ;
static const uint8_t MISO = PIN_SPI_MISO ;
static const uint8_t SCK = PIN_SPI_SCK ;


// SPI1
#define PIN_SPI1_MISO (35)
#define PIN_SPI1_MOSI (30)
#define PIN_SPI1_SCK (29)
Expand Down