|
|
|
@ -79,15 +79,25 @@ void spiBegin() {
|
|
|
|
|
* @details
|
|
|
|
|
*/
|
|
|
|
|
void spiInit(uint8_t spiRate) {
|
|
|
|
|
/**
|
|
|
|
|
* STM32F1 APB1 = 72MHz, APB2 = 36MHz, max SPI speed of this MCU if 18Mhz
|
|
|
|
|
* STM32F1 has 3 SPI ports, SPI1 in APB1, SPI2/SPI3 in APB2
|
|
|
|
|
* so the minimum prescale of SPI1 is DIV4, SPI2/SPI3 is DIV2
|
|
|
|
|
*/
|
|
|
|
|
#if SPI_DEVICE == 1
|
|
|
|
|
#define SPI_CLOCK_MAX SPI_CLOCK_DIV4
|
|
|
|
|
#else
|
|
|
|
|
#define SPI_CLOCK_MAX SPI_CLOCK_DIV2
|
|
|
|
|
#endif
|
|
|
|
|
uint8_t clock;
|
|
|
|
|
switch (spiRate) {
|
|
|
|
|
case SPI_FULL_SPEED: clock = SPI_CLOCK_DIV2 ; break;
|
|
|
|
|
case SPI_FULL_SPEED: clock = SPI_CLOCK_MAX ; break;
|
|
|
|
|
case SPI_HALF_SPEED: clock = SPI_CLOCK_DIV4 ; break;
|
|
|
|
|
case SPI_QUARTER_SPEED: clock = SPI_CLOCK_DIV8 ; break;
|
|
|
|
|
case SPI_EIGHTH_SPEED: clock = SPI_CLOCK_DIV16; break;
|
|
|
|
|
case SPI_SPEED_5: clock = SPI_CLOCK_DIV32; break;
|
|
|
|
|
case SPI_SPEED_6: clock = SPI_CLOCK_DIV64; break;
|
|
|
|
|
default: clock = SPI_CLOCK_DIV2; // Default from the SPI library
|
|
|
|
|
default: clock = SPI_CLOCK_DIV2; // Default from the SPI library
|
|
|
|
|
}
|
|
|
|
|
SPI.setModule(SPI_DEVICE);
|
|
|
|
|
SPI.begin();
|
|
|
|
|