|
@@ -79,15 +79,25 @@ void spiBegin() {
|
79
|
79
|
* @details
|
80
|
80
|
*/
|
81
|
81
|
void spiInit(uint8_t spiRate) {
|
|
82
|
+ /**
|
|
83
|
+ * STM32F1 APB1 = 72MHz, APB2 = 36MHz, max SPI speed of this MCU if 18Mhz
|
|
84
|
+ * STM32F1 has 3 SPI ports, SPI1 in APB1, SPI2/SPI3 in APB2
|
|
85
|
+ * so the minimum prescale of SPI1 is DIV4, SPI2/SPI3 is DIV2
|
|
86
|
+ */
|
|
87
|
+ #if SPI_DEVICE == 1
|
|
88
|
+ #define SPI_CLOCK_MAX SPI_CLOCK_DIV4
|
|
89
|
+ #else
|
|
90
|
+ #define SPI_CLOCK_MAX SPI_CLOCK_DIV2
|
|
91
|
+ #endif
|
82
|
92
|
uint8_t clock;
|
83
|
93
|
switch (spiRate) {
|
84
|
|
- case SPI_FULL_SPEED: clock = SPI_CLOCK_DIV2 ; break;
|
|
94
|
+ case SPI_FULL_SPEED: clock = SPI_CLOCK_MAX ; break;
|
85
|
95
|
case SPI_HALF_SPEED: clock = SPI_CLOCK_DIV4 ; break;
|
86
|
96
|
case SPI_QUARTER_SPEED: clock = SPI_CLOCK_DIV8 ; break;
|
87
|
97
|
case SPI_EIGHTH_SPEED: clock = SPI_CLOCK_DIV16; break;
|
88
|
98
|
case SPI_SPEED_5: clock = SPI_CLOCK_DIV32; break;
|
89
|
99
|
case SPI_SPEED_6: clock = SPI_CLOCK_DIV64; break;
|
90
|
|
- default: clock = SPI_CLOCK_DIV2; // Default from the SPI library
|
|
100
|
+ default: clock = SPI_CLOCK_DIV2; // Default from the SPI library
|
91
|
101
|
}
|
92
|
102
|
SPI.setModule(SPI_DEVICE);
|
93
|
103
|
SPI.begin();
|