Removed some dependencies to the SPI library

This commit is contained in:
Pascal Langer 2017-12-19 22:44:20 +01:00
parent b49584ec16
commit 835cc3d0a2
3 changed files with 12 additions and 10 deletions

View File

@ -19,7 +19,7 @@
#define VERSION_MAJOR 1 #define VERSION_MAJOR 1
#define VERSION_MINOR 1 #define VERSION_MINOR 1
#define VERSION_REVISION 6 #define VERSION_REVISION 6
#define VERSION_PATCH_LEVEL 46 #define VERSION_PATCH_LEVEL 47
//****************** //******************
// Protocols // Protocols
//****************** //******************

View File

@ -51,7 +51,8 @@
#else #else
#include <libmaple/usart.h> #include <libmaple/usart.h>
#include <libmaple/timer.h> #include <libmaple/timer.h>
#include <SPI.h> //#include <libmaple/spi.h>
#include <SPI.h>
#include <EEPROM.h> #include <EEPROM.h>
HardwareTimer HWTimer2(2); HardwareTimer HWTimer2(2);
void PPM_decode(); void PPM_decode();

View File

@ -17,25 +17,26 @@
/********************/ /********************/
#ifdef STM32_BOARD #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() void initSPI2()
{ {
//SPI_DISABLE(); //SPI_DISABLE();
SPI_2.end(); 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. 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.begin(); //Initialize the SPI_2 port.
SPI_2.setBitOrder(MSBFIRST); // Set the SPI_2 bit order SPI2_BASE->CR1 &= ~SPI_CR1_LSBFIRST; // Set the SPI_2 bit order MSB first
SPI_2.setDataMode(SPI_MODE0); // Set the SPI_2 data mode 0 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)
SPI_2.setClockDivider(SPI_CLOCK_DIV8); // Set the speed (36 / 8 = 4.5 MHz SPI_2 speed) 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) void SPI_Write(uint8_t command)
{//working OK {//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)); 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) uint8_t SPI_Read(void)