From 835cc3d0a2daff5ee73fd325a6e833451d713289 Mon Sep 17 00:00:00 2001 From: Pascal Langer Date: Tue, 19 Dec 2017 22:44:20 +0100 Subject: [PATCH] Removed some dependencies to the SPI library --- Multiprotocol/Multiprotocol.h | 2 +- Multiprotocol/Multiprotocol.ino | 3 ++- Multiprotocol/SPI.ino | 17 +++++++++-------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index 52a7fd0..996f55a 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -19,7 +19,7 @@ #define VERSION_MAJOR 1 #define VERSION_MINOR 1 #define VERSION_REVISION 6 -#define VERSION_PATCH_LEVEL 46 +#define VERSION_PATCH_LEVEL 47 //****************** // Protocols //****************** diff --git a/Multiprotocol/Multiprotocol.ino b/Multiprotocol/Multiprotocol.ino index f5ff9a6..01e186e 100644 --- a/Multiprotocol/Multiprotocol.ino +++ b/Multiprotocol/Multiprotocol.ino @@ -51,7 +51,8 @@ #else #include #include - #include + //#include + #include #include HardwareTimer HWTimer2(2); void PPM_decode(); diff --git a/Multiprotocol/SPI.ino b/Multiprotocol/SPI.ino index 16d332b..093674e 100644 --- a/Multiprotocol/SPI.ino +++ b/Multiprotocol/SPI.ino @@ -17,25 +17,26 @@ /********************/ #ifdef STM32_BOARD -SPIClass SPI_2(2); //Create an instance of the SPI Class called SPI_2 that uses the 2nd SPI Port +SPIClass SPI_2(2); //Create an instance of the SPI Class called SPI_2 that uses the 2nd SPI Port void initSPI2() { //SPI_DISABLE(); SPI_2.end(); - SPI2_BASE->CR1 &= ~SPI_CR1_DFF_8_BIT; //8 bits format This bit should be written only when SPI is disabled (SPE = ?0?) for correct operation. - SPI_2.begin(); //Initialize the SPI_2 port. + SPI2_BASE->CR1 &= ~SPI_CR1_DFF_8_BIT; //8 bits format, this bit should be written only when SPI is disabled (SPE = ?0?) for correct operation. + SPI_2.begin(); //Initialize the SPI_2 port. - SPI_2.setBitOrder(MSBFIRST); // Set the SPI_2 bit order - SPI_2.setDataMode(SPI_MODE0); // Set the SPI_2 data mode 0 - SPI_2.setClockDivider(SPI_CLOCK_DIV8); // Set the speed (36 / 8 = 4.5 MHz SPI_2 speed) + SPI2_BASE->CR1 &= ~SPI_CR1_LSBFIRST; // Set the SPI_2 bit order MSB first + SPI2_BASE->CR1 &= ~(SPI_CR1_CPOL|SPI_CR1_CPHA); // Set the SPI_2 data mode 0: Clock idles low, data captured on rising edge (first transition) + SPI2_BASE->CR1 &= ~(SPI_CR1_BR); + SPI2_BASE->CR1 |= SPI_CR1_BR_PCLK_DIV_8; // Set the speed (36 / 8 = 4.5 MHz SPI_2 speed) SPI_CR1_BR_PCLK_DIV_8 } void SPI_Write(uint8_t command) {//working OK - SPI2_BASE->DR = command; //Write the first data item to be transmitted into the SPI_DR register (this clears the TXE flag). + SPI2_BASE->DR = command; //Write the first data item to be transmitted into the SPI_DR register (this clears the TXE flag). while (!(SPI2_BASE->SR & SPI_SR_RXNE)); - command = SPI2_BASE->DR; // ... and read the last received data. + command = SPI2_BASE->DR; // ... and read the last received data. } uint8_t SPI_Read(void)