Skip to content

Commit 3d8c68a

Browse files
authored
Merge pull request #441 from adafruit/SPIM3-variant
add macro SPI_32MHZ_INTERFACE to variant to select SPI or SPI1 to use 32mhz SPIM3
2 parents d72fe7e + 050129e commit 3d8c68a

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

libraries/SPI/SPI.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,13 +254,30 @@ void SPIClass::detachInterrupt() {
254254
// Should be disableInterrupt()
255255
}
256256

257-
#if SPI_INTERFACES_COUNT > 0
257+
// default to 0
258+
#ifndef SPI_32MHZ_INTERFACE
259+
#define SPI_32MHZ_INTERFACE 0
260+
#endif
261+
262+
#if SPI_32MHZ_INTERFACE == 0
263+
#define _SPI_DEV NRF_SPIM3 // 32 Mhz
264+
#define _SPI1_DEV NRF_SPIM2
265+
266+
#elif SPI_32MHZ_INTERFACE == 1
267+
#define _SPI_DEV NRF_SPIM2
268+
#define _SPI1_DEV NRF_SPIM3 // 32 Mhz
269+
270+
#else
271+
#error "not supported yet"
272+
#endif
273+
274+
#if SPI_INTERFACES_COUNT >= 1
258275
// use SPIM3 for highspeed 32Mhz
259-
SPIClass SPI(NRF_SPIM3, PIN_SPI_MISO, PIN_SPI_SCK, PIN_SPI_MOSI);
276+
SPIClass SPI(_SPI_DEV, PIN_SPI_MISO, PIN_SPI_SCK, PIN_SPI_MOSI);
260277
#endif
261278

262-
#if SPI_INTERFACES_COUNT > 1
263-
SPIClass SPI1(NRF_SPIM2, PIN_SPI1_MISO, PIN_SPI1_SCK, PIN_SPI1_MOSI);
279+
#if SPI_INTERFACES_COUNT >= 2
280+
SPIClass SPI1(_SPI1_DEV, PIN_SPI1_MISO, PIN_SPI1_SCK, PIN_SPI1_MOSI);
264281
#endif
265282

266283
#endif // NRF52840_XXAA

variants/clue_nrf52840/variant.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ static const uint8_t A7 = PIN_A7 ;
9393
*/
9494
#define SPI_INTERFACES_COUNT 2
9595

96+
// nRF52840 has only one SPIM3 runing at highspeed 32Mhz
97+
// This assign SPIM3 to either: SPI (0), SPI1 (1).
98+
// If not defined, default to 0 or SPI.
99+
#define SPI_32MHZ_INTERFACE 1
100+
101+
// SPI
96102
#define PIN_SPI_MISO (14)
97103
#define PIN_SPI_MOSI (15)
98104
#define PIN_SPI_SCK (13)
@@ -102,7 +108,7 @@ static const uint8_t MOSI = PIN_SPI_MOSI ;
102108
static const uint8_t MISO = PIN_SPI_MISO ;
103109
static const uint8_t SCK = PIN_SPI_SCK ;
104110

105-
111+
// SPI1
106112
#define PIN_SPI1_MISO (35)
107113
#define PIN_SPI1_MOSI (30)
108114
#define PIN_SPI1_SCK (29)

0 commit comments

Comments
 (0)