|
|
|
@ -79,9 +79,19 @@ 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;
|
|
|
|
|