From 98341bfb821d25821e4fc60511b50405cb874c2b Mon Sep 17 00:00:00 2001
From: Cristian Maglie <c.maglie@arduino.cc>
Date: Thu, 11 Sep 2014 22:25:49 +0200
Subject: [PATCH]  Added SPI clock divisor for compatibility with legacy SPI
 library for AVR

---
 libraries/SPI/SPI.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/libraries/SPI/SPI.h b/libraries/SPI/SPI.h
index 34d0e1ba..02ac74f3 100644
--- a/libraries/SPI/SPI.h
+++ b/libraries/SPI/SPI.h
@@ -93,4 +93,16 @@ void SPIClass::transfer(void *buf, size_t count)
   extern SPIClass SPI;
 #endif
 
+// For compatibility with sketches designed for AVR @ 16 MHz
+// New programs should use SPI.beginTransaction to set the SPI clock
+#if F_CPU == 48000000
+  #define SPI_CLOCK_DIV2   6
+  #define SPI_CLOCK_DIV4   12
+  #define SPI_CLOCK_DIV8   24
+  #define SPI_CLOCK_DIV16  48
+  #define SPI_CLOCK_DIV32  96
+  #define SPI_CLOCK_DIV64  192
+  #define SPI_CLOCK_DIV128 255
+#endif
+
 #endif
-- 
GitLab