Skip to content

Commit 7a057bb

Browse files
committed
fix SPI CLOCK DIV with F_CPU @ 64MHz
1 parent ca4cbe9 commit 7a057bb

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

libraries/SPI/SPI.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,17 +188,18 @@ void SPIClass::setClockDivider(uint8_t div)
188188
{
189189
uint32_t clockFreq;
190190

191-
if (div >= SPI_CLOCK_DIV128) {
191+
// Adafruit Note: nrf52 run at 64MHz
192+
if (div >= SPI_CLOCK_DIV512) {
192193
clockFreq = SPI_FREQUENCY_FREQUENCY_K125;
193-
} else if (div >= SPI_CLOCK_DIV64) {
194+
} else if (div >= SPI_CLOCK_DIV256) {
194195
clockFreq = SPI_FREQUENCY_FREQUENCY_K250;
195-
} else if (div >= SPI_CLOCK_DIV32) {
196+
} else if (div >= SPI_CLOCK_DIV128) {
196197
clockFreq = SPI_FREQUENCY_FREQUENCY_K500;
197-
} else if (div >= SPI_CLOCK_DIV16) {
198+
} else if (div >= SPI_CLOCK_DIV64) {
198199
clockFreq = SPI_FREQUENCY_FREQUENCY_M1;
199-
} else if (div >= SPI_CLOCK_DIV8) {
200+
} else if (div >= SPI_CLOCK_DIV32) {
200201
clockFreq = SPI_FREQUENCY_FREQUENCY_M2;
201-
} else if (div >= SPI_CLOCK_DIV4) {
202+
} else if (div >= SPI_CLOCK_DIV16) {
202203
clockFreq = SPI_FREQUENCY_FREQUENCY_M4;
203204
} else {
204205
clockFreq = SPI_FREQUENCY_FREQUENCY_M8;

libraries/SPI/SPI.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,16 +137,18 @@ void SPIClass::transfer(void *buf, size_t count)
137137
extern SPIClass SPI;
138138
#endif
139139

140-
// For compatibility with sketches designed for AVR @ 16 MHz
140+
// For compatibility with sketches designed for AVR @ 64 MHz
141141
// New programs should use SPI.beginTransaction to set the SPI clock
142-
#if F_CPU == 16000000
142+
#if F_CPU == 64000000 // feather52 run @ 64Mhz
143143
#define SPI_CLOCK_DIV2 2
144144
#define SPI_CLOCK_DIV4 4
145145
#define SPI_CLOCK_DIV8 8
146146
#define SPI_CLOCK_DIV16 16
147147
#define SPI_CLOCK_DIV32 32
148148
#define SPI_CLOCK_DIV64 64
149149
#define SPI_CLOCK_DIV128 128
150+
#define SPI_CLOCK_DIV256 256
151+
#define SPI_CLOCK_DIV512 512
150152
#endif
151153

152-
#endif
154+
#endif

0 commit comments

Comments
 (0)