예제 #1
0
파일: main.c 프로젝트: j-a-r-i/StmMeasure
//------------------------------------------------------------------------------
void uart_init(void)
{
  uart1Handle.Instance = USART1;
  uart1Handle.Init.BaudRate = 9600;
  uart1Handle.Init.WordLength = UART_WORDLENGTH_8B;
  uart1Handle.Init.StopBits = UART_STOPBITS_1;
  uart1Handle.Init.Parity = UART_PARITY_NONE;
  uart1Handle.Init.Mode = UART_MODE_TX_RX;
  uart1Handle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  uart1Handle.Init.OverSampling = UART_OVERSAMPLING_16;
  uart1Handle.Init.OneBitSampling = UART_ONEBIT_SAMPLING_DISABLED ;
  uart1Handle.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
  HAL_UART_Init(&uart1Handle);

  spi1Handle.Instance = SPI1;
  spi1Handle.Init.Mode = SPI_MODE_SLAVE;
  spi1Handle.Init.Direction = SPI_DIRECTION_2LINES;
  spi1Handle.Init.DataSize = SPI_DATASIZE_8BIT;
  spi1Handle.Init.CLKPolarity = SPI_POLARITY_LOW;
  spi1Handle.Init.CLKPhase = SPI_PHASE_1EDGE;
  spi1Handle.Init.NSS = SPI_NSS_SOFT;
  spi1Handle.Init.FirstBit = SPI_FIRSTBIT_MSB;
  spi1Handle.Init.TIMode = SPI_TIMODE_DISABLED;
  spi1Handle.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;
  spi1Handle.Init.CRCPolynomial = 7;
  spi1Handle.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
  spi1Handle.Init.NSSPMode = SPI_NSS_PULSE_DISABLED;
  HAL_SPI_Init(&spi1Handle);
  
}
예제 #2
0
/**
  * @brief SPIx Bus initialization
  * @param None
  * @retval None
  */
static void SPIx_Init(void)
{
  if(HAL_SPI_GetState(&heval_Spi) == HAL_SPI_STATE_RESET)
  {
    /* SPI Config */
    heval_Spi.Instance = EVAL_SPIx;
    /* SPI baudrate is set to 16 MHz (PCLK2/SPI_BaudRatePrescaler = 32/2 = 16 MHz) 
    to verify these constraints:
    HX8347D LCD SPI interface max baudrate is  50MHz for write and 6.66MHz for read
    PCLK1 frequency is set to 32 MHz 
    - SD card SPI interface max baudrate is 25MHz for write/read
    */
    heval_Spi.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
    heval_Spi.Init.Direction = SPI_DIRECTION_2LINES;
    heval_Spi.Init.CLKPhase = SPI_PHASE_2EDGE;
    heval_Spi.Init.CLKPolarity = SPI_POLARITY_HIGH;
    heval_Spi.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
    heval_Spi.Init.CRCPolynomial = 7;
    heval_Spi.Init.DataSize = SPI_DATASIZE_8BIT;
    heval_Spi.Init.FirstBit = SPI_FIRSTBIT_MSB;
    heval_Spi.Init.NSS = SPI_NSS_SOFT;
    heval_Spi.Init.TIMode = SPI_TIMODE_DISABLE;
    heval_Spi.Init.Mode = SPI_MODE_MASTER;
    
    SPIx_MspInit(&heval_Spi);
    HAL_SPI_Init(&heval_Spi);
  }
}
/* SPI3 init function */
static void MX_SPI3_Init(void)
{

    // The Fpclk is at 36MHz

  hspi3.Instance = SPI3;
  hspi3.Init.Mode = SPI_MODE_MASTER;
  hspi3.Init.Direction = SPI_DIRECTION_1LINE;
  hspi3.Init.DataSize = SPI_DATASIZE_8BIT;
  hspi3.Init.CLKPolarity = SPI_POLARITY_HIGH;
  hspi3.Init.CLKPhase = SPI_PHASE_2EDGE;
  hspi3.Init.NSS = SPI_NSS_HARD_OUTPUT;

  // 36MHz/2 = 18MHz
  // 36MHz/4 = 9MHz
  // 36MHz/8 = 4.5MHz
  // 36MHz/16 = 2.25MHz
  // 36MHz/32 = 1.125MHz
  // 36MHz/64 = 562.5KHz
  // 36MHz/128 = 281.25KHz
  // 36MHz/256 = 140.625KHz

  hspi3.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64;
  hspi3.Init.FirstBit = SPI_FIRSTBIT_MSB;
  hspi3.Init.TIMode = SPI_TIMODE_DISABLE;
  hspi3.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
  hspi3.Init.CRCPolynomial = 10;
  if (HAL_SPI_Init(&hspi3) != HAL_OK)
  {
    Error_Handler();
  }

}
/**
  * @brief  SPIx Bus initialization
  */
static void SPIx_Init(void)
{
  if(HAL_SPI_GetState(&SpiHandle) == HAL_SPI_STATE_RESET)
  {
    /* SPI configuration -----------------------------------------------------*/
    SpiHandle.Instance = DISCOVERY_SPIx;
    /* SPI baudrate is set to 5.6 MHz (PCLK2/SPI_BaudRatePrescaler = 90/16 = 5.625 MHz) 
       to verify these constraints:
       - ILI9341 LCD SPI interface max baudrate is 10MHz for write and 6.66MHz for read
       - l3gd20 SPI interface max baudrate is 10MHz for write/read
       - PCLK2 frequency is set to 90 MHz 
    */  
    SpiHandle.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16;

    /* On STM32F429I-Discovery, LCD ID cannot be read then keep a common configuration */
    /* for LCD and GYRO (SPI_DIRECTION_2LINES) */
    /* Note: To read a register a LCD, SPI_DIRECTION_1LINE should be set */
    SpiHandle.Init.Direction      = SPI_DIRECTION_2LINES;
    SpiHandle.Init.CLKPhase       = SPI_PHASE_1EDGE;
    SpiHandle.Init.CLKPolarity    = SPI_POLARITY_LOW;
    SpiHandle.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;
    SpiHandle.Init.CRCPolynomial  = 7;
    SpiHandle.Init.DataSize       = SPI_DATASIZE_8BIT;
    SpiHandle.Init.FirstBit       = SPI_FIRSTBIT_MSB;
    SpiHandle.Init.NSS            = SPI_NSS_SOFT;
    SpiHandle.Init.TIMode         = SPI_TIMODE_DISABLED;
    SpiHandle.Init.Mode           = SPI_MODE_MASTER;
  
    SPIx_MspInit(&SpiHandle);
    HAL_SPI_Init(&SpiHandle);
  } 
}
예제 #5
0
/**
 * Initialize Sharp LCD
 * @param void No arguments
 * @return void No return
 */
void SharpLcd_Init(void)
{
	// Local variables
	GPIO_InitTypeDef GPIO_InitStruct;

	// Init GPIO
	__GPIOA_CLK_ENABLE();
	__GPIOC_CLK_ENABLE();
	__GPIOD_CLK_ENABLE();

	// Control Pins
	GPIO_InitStruct.Pin = s_SHARPLCD__SCS;
	GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
	GPIO_InitStruct.Pull = GPIO_PULLDOWN;
	GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
	HAL_GPIO_Init(s_SHARPLCD__SCS_PORT, &GPIO_InitStruct);

	GPIO_InitStruct.Pin = s_SHARPLCD__DISP;
	GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
	GPIO_InitStruct.Pull = GPIO_PULLDOWN;
	GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
	HAL_GPIO_Init(s_SHARPLCD__DISP_PORT, &GPIO_InitStruct);

	GPIO_InitStruct.Pin = s_SHARPLCD__EXTCOMIN;
	GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
	GPIO_InitStruct.Pull = GPIO_PULLDOWN;
	GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
	HAL_GPIO_Init(s_SHARPLCD__VCOM_PORT, &GPIO_InitStruct);

	// SPI Pins
	GPIO_InitStruct.Pin = s_SHARPLCD__SCLK | s_SHARPLCD__SI;
	GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
	GPIO_InitStruct.Pull = GPIO_NOPULL;
	GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
	GPIO_InitStruct.Alternate = GPIO_AF6_SPI3;
	HAL_GPIO_Init(s_SHARPLCD__SPI_PORT, &GPIO_InitStruct);

	// Set initial state of GPIO
	s_SHARPLCD__DISP_RESET();
	s_SHARPLCD__SCS_RESET();
	s_SHARPLCD__EXTCOMIN_RESET();

	// Init SPI
	__SPI3_CLK_ENABLE();

	g_SharpLcd_SpiHandle.Instance = SPI3;
	g_SharpLcd_SpiHandle.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32;
	g_SharpLcd_SpiHandle.Init.Mode = SPI_MODE_MASTER;
	g_SharpLcd_SpiHandle.Init.Direction = SPI_DIRECTION_2LINES;
	g_SharpLcd_SpiHandle.Init.DataSize = SPI_DATASIZE_8BIT;
	g_SharpLcd_SpiHandle.Init.CLKPolarity = SPI_POLARITY_LOW;
	g_SharpLcd_SpiHandle.Init.CLKPhase = SPI_PHASE_1EDGE;
	g_SharpLcd_SpiHandle.Init.NSS = SPI_NSS_SOFT;
	g_SharpLcd_SpiHandle.Init.FirstBit = SPI_FIRSTBIT_LSB;
	g_SharpLcd_SpiHandle.Init.TIMode = SPI_TIMODE_DISABLED;
	g_SharpLcd_SpiHandle.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;
	g_SharpLcd_SpiHandle.Init.CRCPolynomial = 10;
	HAL_SPI_Init(&g_SharpLcd_SpiHandle);

}
예제 #6
0
/**
  * @brief SPI1 Initialization Function
  * @param None
  * @retval None
  */
static void MX_SPI1_Init(void)
{

  /* USER CODE BEGIN SPI1_Init 0 */

  /* USER CODE END SPI1_Init 0 */

  /* USER CODE BEGIN SPI1_Init 1 */

  /* USER CODE END SPI1_Init 1 */
  /* SPI1 parameter configuration*/
  hspi1.Instance = SPI1;
  hspi1.Init.Mode = SPI_MODE_MASTER;
  hspi1.Init.Direction = SPI_DIRECTION_2LINES;
  hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
  hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
  hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
  hspi1.Init.NSS = SPI_NSS_SOFT;
  hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;
  hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
  hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
  hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
  hspi1.Init.CRCPolynomial = 10;
  if (HAL_SPI_Init(&hspi1) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN SPI1_Init 2 */

  /* USER CODE END SPI1_Init 2 */

}
예제 #7
0
/*====================================================================================================*/
static void MPU9250_SetSpeed( uint8_t SpeedSel )
{
  __HAL_SPI_DISABLE(&SPI_HandleStruct);
  SPI_HandleStruct.Init.BaudRatePrescaler = SpeedSel;
  HAL_SPI_Init(&SPI_HandleStruct);
  __HAL_SPI_ENABLE(&SPI_HandleStruct);
}
예제 #8
0
/**
  * @brief  Initializes SPI HAL.
  * @retval None
  */
static void SPIx_Init(void)
{
  if(HAL_SPI_GetState(&hnucleo_Spi) == HAL_SPI_STATE_RESET)
  {
    /* SPI Config */
    hnucleo_Spi.Instance = NUCLEO_SPIx;
      /* SPI baudrate is set to 8 MHz maximum (PCLK2/SPI_BaudRatePrescaler = 64/8 = 8 MHz) 
       to verify these constraints:
          - ST7735 LCD SPI interface max baudrate is 15MHz for write and 6.66MHz for read
            Since the provided driver doesn't use read capability from LCD, only constraint 
            on write baudrate is considered.
          - SD card SPI interface max baudrate is 25MHz for write/read
          - PCLK2 max frequency is 32 MHz 
       */
    hnucleo_Spi.Init.BaudRatePrescaler  = SPI_BAUDRATEPRESCALER_8;
    hnucleo_Spi.Init.Direction          = SPI_DIRECTION_2LINES;
    hnucleo_Spi.Init.CLKPhase           = SPI_PHASE_1EDGE;
    hnucleo_Spi.Init.CLKPolarity        = SPI_POLARITY_LOW;
    hnucleo_Spi.Init.CRCCalculation     = SPI_CRCCALCULATION_DISABLE;
    hnucleo_Spi.Init.CRCPolynomial      = 7;
    hnucleo_Spi.Init.DataSize           = SPI_DATASIZE_8BIT;
    hnucleo_Spi.Init.FirstBit           = SPI_FIRSTBIT_MSB;
    hnucleo_Spi.Init.NSS                = SPI_NSS_SOFT;
    hnucleo_Spi.Init.TIMode             = SPI_TIMODE_DISABLE;
    hnucleo_Spi.Init.Mode               = SPI_MODE_MASTER;
    
    SPIx_MspInit();
    HAL_SPI_Init(&hnucleo_Spi);
  }
}
/**
  * @brief SPIx Bus initialization
  * @param None
  * @retval None
  */
static void SPIx_Init(void)
{
  if(HAL_SPI_GetState(&SpiHandle) == HAL_SPI_STATE_RESET)
  {
    /* SPI Config */
    SpiHandle.Instance = DISCOVERY_SPIx;
    /* SPI baudrate is set to 5.6 MHz (PCLK2/SPI_BaudRatePrescaler = 90/16 = 5.625 MHz)
      to verify these constraints:
      ILI9341 LCD SPI interface max baudrate is 10MHz for write and 6.66MHz for read
      l3gd20 SPI interface max baudrate is 10MHz for write/read
      PCLK2 frequency is set to 90 MHz
  */
    SpiHandle.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16;
    SpiHandle.Init.Direction = SPI_DIRECTION_2LINES;
    SpiHandle.Init.CLKPhase = SPI_PHASE_1EDGE;
    SpiHandle.Init.CLKPolarity = SPI_POLARITY_LOW;
    SpiHandle.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;
    SpiHandle.Init.CRCPolynomial = 7;
    SpiHandle.Init.DataSize = SPI_DATASIZE_8BIT;
    SpiHandle.Init.FirstBit = SPI_FIRSTBIT_MSB;
    SpiHandle.Init.NSS = SPI_NSS_SOFT;
    SpiHandle.Init.TIMode = SPI_TIMODE_DISABLED;
    SpiHandle.Init.Mode = SPI_MODE_MASTER;

    SPIx_MspInit(&SpiHandle);
    HAL_SPI_Init(&SpiHandle);
  }
}
예제 #10
0
void SpiInit( Spi_t *obj, PinNames mosi, PinNames miso, PinNames sclk, PinNames nss )
{
    __HAL_RCC_SPI1_FORCE_RESET( );
    __HAL_RCC_SPI1_RELEASE_RESET( );

    __HAL_RCC_SPI1_CLK_ENABLE( );

    obj->Spi.Instance = ( SPI_TypeDef *) SPI1_BASE;

    GpioInit( &obj->Mosi, mosi, PIN_ALTERNATE_FCT, PIN_PUSH_PULL, PIN_PULL_DOWN, GPIO_AF5_SPI1 );
    GpioInit( &obj->Miso, miso, PIN_ALTERNATE_FCT, PIN_PUSH_PULL, PIN_PULL_DOWN, GPIO_AF5_SPI1 );
    GpioInit( &obj->Sclk, sclk, PIN_ALTERNATE_FCT, PIN_PUSH_PULL, PIN_PULL_DOWN, GPIO_AF5_SPI1 );

    if( nss != NC )
    {
        GpioInit( &obj->Nss, nss, PIN_ALTERNATE_FCT, PIN_PUSH_PULL, PIN_PULL_UP, GPIO_AF5_SPI1 );
    }
    else
    {
        obj->Spi.Init.NSS = SPI_NSS_SOFT;
    }

    if( nss == NC )
    {
        SpiFormat( obj, SPI_DATASIZE_8BIT, SPI_POLARITY_LOW, SPI_PHASE_1EDGE, 0 );
    }
    else
    {
        SpiFormat( obj, SPI_DATASIZE_8BIT, SPI_POLARITY_LOW, SPI_PHASE_1EDGE, 1 );
    }
    SpiFrequency( obj, 10000000 );

    HAL_SPI_Init( &obj->Spi );
}
예제 #11
0
/*====================================================================================================*/
void MPU9250_SetSpeed( uint8_t speedSel )
{
  __HAL_SPI_DISABLE(&MPUPx_InitStruct);
  MPUPx_InitStruct.Init.BaudRatePrescaler = speedSel;
  HAL_SPI_Init(&MPUPx_InitStruct);
  __HAL_SPI_ENABLE(&MPUPx_InitStruct);
}
예제 #12
0
파일: spi.cpp 프로젝트: jaggies/matchbox
Spi::Spi(Bus bus, const Config& config)
        : _bus(bus), _txCallback(0), _rxCallback(0), _txrxCallback(0), _txArgs(0),
          _rxArgs(0), _txrxArgs(0) {
    bzero(&_spi, sizeof(_spi));
    _spi.Instance = _busMap[bus];
    _spi.Init.Mode = config.mode == Master ? SPI_MODE_MASTER : SPI_MODE_SLAVE;
    _spi.Init.Direction = _dirMap[config.dir];
    _spi.Init.DataSize = config.size == S8 ? SPI_DATASIZE_8BIT : SPI_DATASIZE_16BIT;
    _spi.Init.CLKPolarity = config.polarity == LOW ? SPI_POLARITY_LOW : SPI_POLARITY_HIGH;
    _spi.Init.CLKPhase = config.phase == Rising ? SPI_PHASE_1EDGE : SPI_PHASE_2EDGE;
    _spi.Init.NSS = config.ss == SOFTWARE ? SPI_NSS_SOFT
            : (config.ss == HARD_OUTPUT ? SPI_NSS_HARD_OUTPUT : SPI_NSS_HARD_INPUT);
    _spi.Init.BaudRatePrescaler = clkdivs[config.div];
    _spi.Init.FirstBit = config.order == MSB_FIRST ? SPI_FIRSTBIT_MSB : SPI_FIRSTBIT_LSB;
    _spi.Init.TIMode = SPI_TIMODE_DISABLE;
    _spi.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
    _spi.Init.CRCPolynomial = 10;
    HAL_SPI_Init(&_spi);

    // Enable interrupts to allow async transmit/receive
    HAL_NVIC_SetPriority(irqMap[bus], 15 /* low preempt priority */, 0 /* high sub-priority*/);
    HAL_NVIC_EnableIRQ(irqMap[bus]);

    // Keep track of Spi instance
    spiMap[bus] = this;
}
예제 #13
0
/*********************************************************************
 * @fn		 SPI1_Init
 *
 * @brief 	 SPIx Bus initialization
 *
 * @param 	None
 *
 * @return	void
 */
void SPI1_Init(void)
{
  SX1276.Spi.Spi = ( SPI_TypeDef* )SPI1_BASE;

  if(HAL_SPI_GetState(&SpiHandle) == HAL_SPI_STATE_RESET)
  {
    /* SPI Config */
    SpiHandle.Instance = SPIx;

    /* On STM32L0538-DISCO, EPD ID cannot be read then keep a common configuration */
    /* for EPD (SPI_DIRECTION_2LINES) */
    /* Note: To read a register a EPD, SPI_DIRECTION_1LINE should be set */
    SpiHandle.Init.Mode               = SPI_MODE_MASTER;
    SpiHandle.Init.Direction          = SPI_DIRECTION_2LINES;
    SpiHandle.Init.BaudRatePrescaler  = SPI_BAUDRATEPRESCALER_8;
    SpiHandle.Init.DataSize           = SPI_DATASIZE_8BIT;
    SpiHandle.Init.CLKPhase           = SPI_PHASE_1EDGE;//SPI_PHASE_2EDGE;
    SpiHandle.Init.CLKPolarity        = SPI_POLARITY_LOW;//SPI_POLARITY_HIGH;SPI_POLARITY_LOW
    SpiHandle.Init.FirstBit           = SPI_FIRSTBIT_MSB;
    SpiHandle.Init.NSS                = SPI_NSS_SOFT;
    SpiHandle.Init.CRCCalculation     = SPI_CRCCALCULATION_DISABLED;
    SpiHandle.Init.CRCPolynomial      = 7;
    SpiHandle.Init.TIMode             = SPI_TIMODE_DISABLED;

    SPI1_MspInit(&SpiHandle);
    HAL_SPI_Init(&SpiHandle);
  }
}
예제 #14
0
//SPI6 peripheral initialization. SPI6 is available on the Expansion connector
void init_spi6(void)
{

	//Configure SPI6 in Mode 0, Master
	//CPOL = 0 --> clock is low when idle
	//CPHA = 0 --> data is sampled at the first edge

	spi6_handle.Instance = SPI6;
	spi6_handle.Init.Direction = SPI_DIRECTION_2LINES; 				// Full duplex
	spi6_handle.Init.Mode = SPI_MODE_MASTER;     					// Master
	spi6_handle.Init.DataSize = SPI_DATASIZE_8BIT; 					// 8bits words
	spi6_handle.Init.CLKPolarity = SPI_POLARITY_LOW;        		// clock is low when idle (CPOL = 0)
	spi6_handle.Init.CLKPhase = SPI_PHASE_1EDGE;      				// data sampled at first (rising) edge (CPHA = 0)
	spi6_handle.Init.NSS = SPI_NSS_HARD_OUTPUT; 					// uses hardware slave select
	spi6_handle.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_4; 	// SPI frequency is APB2 frequency / 4	****ToDo Adjust!
	spi6_handle.Init.FirstBit = SPI_FIRSTBIT_MSB;					// data is transmitted MSB first
	spi6_handle.Init.TIMode = SPI_TIMODE_DISABLED;					//
	spi6_handle.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;
	spi6_handle.Init.CRCPolynomial = 7;

	if(HAL_SPI_Init(&spi6_handle) != HAL_OK)
	{
		flexsea_error(SE_INIT_SPI);
	}
}
예제 #15
0
파일: imu.c 프로젝트: Hom-Wang/SmartIMU
/**
 *  @brief  IMU_Config
 */
void IMU_Config( void )
{
  hImu.pTxBuf = IMU_TX_BUFFER;
  hImu.pRxBuf = IMU_RX_BUFFER;

#if defined(__MPU9250_H)
  MPU92_Config();
#endif

#if defined(__LPS22HB_H)
  LPS22_Config();
#endif

  /* SPI Init ****************************************************************/
  hImu.handle->Instance               = IMU_SPIx;
  hImu.handle->Init.Mode              = SPI_MODE_MASTER;
  hImu.handle->Init.Direction         = SPI_DIRECTION_2LINES;
  hImu.handle->Init.DataSize          = SPI_DATASIZE_8BIT;
  hImu.handle->Init.CLKPolarity       = SPI_POLARITY_HIGH;
  hImu.handle->Init.CLKPhase          = SPI_PHASE_2EDGE;
  hImu.handle->Init.NSS               = SPI_NSS_SOFT;
  hImu.handle->Init.BaudRatePrescaler = IMU_SPIx_SPEED_LOW;
  hImu.handle->Init.FirstBit          = SPI_FIRSTBIT_MSB;
  hImu.handle->Init.TIMode            = SPI_TIMODE_DISABLE;
  hImu.handle->Init.CRCCalculation    = SPI_CRCCALCULATION_ENABLE;
  hImu.handle->Init.CRCPolynomial     = 7;
  HAL_SPI_Init(hImu.handle);

  __HAL_SPI_ENABLE(hImu.handle);
}
예제 #16
0
/*====================================================================================================*/
void IMU_SetSpeed( uint8_t speedSel )
{
  __HAL_SPI_DISABLE(&IMU_HandleStruct);
  IMU_HandleStruct.Init.BaudRatePrescaler = speedSel;
  HAL_SPI_Init(&IMU_HandleStruct);
  __HAL_SPI_ENABLE(&IMU_HandleStruct);
}
/**
 * @brief  Configures LIS3DSH
 * @param  InitTypeDef: Specifies the configuration.
 * @retval None
 */
void LIS3DSH_init(LIS3DSH_InitTypeDef li) {

	GPIO_InitTypeDef GPIO_InitStructure;

	/* Configure the LIS3DSH Control pins --------------------------------*/
	/* Enable CS GPIO clock and configure GPIO pin for LIS3DSH Chip select */
	LIS3DSH_SPI_CS_GPIO_CLK_ENABLE();

	/* Configure GPIO PIN for LIS Chip select */
	GPIO_InitStructure.Pin = LIS3DSH_SPI_CS_PIN;
	GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
	GPIO_InitStructure.Pull = GPIO_NOPULL;
	GPIO_InitStructure.Speed = GPIO_SPEED_MEDIUM;
	HAL_GPIO_Init(LIS3DSH_SPI_CS_GPIO_PORT, &GPIO_InitStructure);

	/* Deselect: Chip Select high */
	/* SPI start when the chip select is low */
	LIS3DSH_CS_HIGH();

	/* Configure the SPI1 to communicate with the accelerometer */
	if (HAL_SPI_GetState(&SpiHandle) == HAL_SPI_STATE_RESET)
	{
		/* SPI configuration -----------------------------------------------------*/
		SpiHandle.Instance = LIS3DSH_SPI;
		SpiHandle.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16;
		SpiHandle.Init.Direction = SPI_DIRECTION_2LINES;
		SpiHandle.Init.CLKPhase = SPI_PHASE_1EDGE;
		SpiHandle.Init.CLKPolarity = SPI_POLARITY_LOW;
		SpiHandle.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;
		SpiHandle.Init.CRCPolynomial = 7;
		SpiHandle.Init.DataSize = SPI_DATASIZE_8BIT;
		SpiHandle.Init.FirstBit = SPI_FIRSTBIT_MSB;
		SpiHandle.Init.NSS = SPI_NSS_SOFT;
		SpiHandle.Init.TIMode = SPI_TIMODE_DISABLED;
		SpiHandle.Init.Mode = SPI_MODE_MASTER;

		/* SPI low level configuration */
		/* Enable the SPI peripheral */
		LIS3DSH_SPI_CLK_ENABLE();

		/* Enable SCK, MOSI and MISO GPIO clocks */
		LIS3DSH_SPI_GPIO_CLK_ENABLE();

		/* SPI SCK, MOSI, MISO pin configuration */
		GPIO_InitStructure.Pin = (LIS3DSH_SPI_SCK_PIN | LIS3DSH_SPI_MISO_PIN
				| LIS3DSH_SPI_MOSI_PIN);
		GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
		GPIO_InitStructure.Pull = GPIO_PULLDOWN;
		GPIO_InitStructure.Speed = GPIO_SPEED_FAST;
		GPIO_InitStructure.Alternate = LIS3DSH_SPI_AF;
		HAL_GPIO_Init(LIS3DSH_SPI_GPIO_PORT, &GPIO_InitStructure);

		HAL_SPI_Init(&SpiHandle);
	}

	/* Configures the inner register of the accelerometer */
	LIS3DSH_writeRegister(LIS3DSH_CTRL_REG4_ADDR, li.OutputDataRate | li.Axes_Enable | li.BlockDataUpdate);
	LIS3DSH_writeRegister(LIS3DSH_CTRL_REG5_ADDR, li.FullScale);
}
예제 #18
0
void spiInit(void)
{
    SIGNAL_TIMER_CHANNEL_GPIO_PORT();
    SPI_CLK_ENABLE();

    GPIO_InitTypeDef spiGpioInit = { 0 };

    // SPI has GPIOB 3..5
    spiGpioInit.Pin  = GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5;
    spiGpioInit.Mode = GPIO_MODE_AF_PP;
    spiGpioInit.Pull = GPIO_NOPULL;
    HAL_GPIO_Init(SPI_GPIO_PORT, &spiGpioInit);

    // Initialize SPI1 module
    g_spiInit.Instance = SPI;
    g_spiInit.Init.BaudRatePrescaler   = SPI_BAUDRATEPRESCALER_8;
    g_spiInit.Init.CLKPhase            = SPI_PHASE_1EDGE;
    g_spiInit.Init.CLKPolarity         = SPI_POLARITY_LOW;
    g_spiInit.Init.CRCCalculation      = SPI_CRCCALCULATION_DISABLE;
    g_spiInit.Init.DataSize            = SPI_DATASIZE_8BIT;
    g_spiInit.Init.FirstBit            = SPI_FIRSTBIT_MSB;
    g_spiInit.Init.Mode                = SPI_MODE_MASTER;
    g_spiInit.Init.NSS                 = SPI_NSS_SOFT;
    g_spiInit.Init.TIMode              = SPI_TIMODE_DISABLE;
    if (HAL_SPI_Init(&g_spiInit) != HAL_OK)
    {
        ERROR_SPI(ED_SPI_FAILED_TO_INITIALIZE_SPI);
    }

    // Initialize DMA for SPI1
    g_dmaSpiRx.Instance                 = SPI_DMA_RX_INSTANCE;
    g_dmaSpiRx.Init.Request             = DMA_REQUEST_1;
    g_dmaSpiRx.Init.Direction           = DMA_PERIPH_TO_MEMORY;
    g_dmaSpiRx.Init.PeriphInc           = DMA_PINC_DISABLE;
    g_dmaSpiRx.Init.MemInc              = DMA_MINC_ENABLE;
    g_dmaSpiRx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
    g_dmaSpiRx.Init.MemDataAlignment    = DMA_MDATAALIGN_BYTE;
    g_dmaSpiRx.Init.Mode                = DMA_NORMAL;
    g_dmaSpiRx.Init.Priority            = DMA_PRIORITY_MEDIUM;
    if (HAL_DMA_Init(&g_dmaSpiRx) != HAL_OK)
    {
        ERROR_SPI(ED_SPI_FAILED_TO_INITIALIZE_SPI);
    }

    g_dmaSpiTx.Instance                 = SPI_DMA_TX_INSTANCE;
    g_dmaSpiTx.Init.Request             = DMA_REQUEST_1;
    g_dmaSpiTx.Init.Direction           = DMA_MEMORY_TO_PERIPH;
    g_dmaSpiTx.Init.PeriphInc           = DMA_PINC_DISABLE;
    g_dmaSpiTx.Init.MemInc              = DMA_MINC_ENABLE;
    g_dmaSpiTx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
    g_dmaSpiTx.Init.MemDataAlignment    = DMA_MDATAALIGN_BYTE;
    g_dmaSpiTx.Init.Mode                = DMA_NORMAL;
    g_dmaSpiTx.Init.Priority            = DMA_PRIORITY_MEDIUM;
    if (HAL_DMA_Init(&g_dmaSpiTx) != HAL_OK)
    {
        ERROR_SPI(ED_SPI_FAILED_TO_INITIALIZE_SPI);
    }
}
예제 #19
0
/**
 * @brief   Initializes the SPI2 for use with FPGA config
 * @param   None
 * @retval  None
 */
ErrorStatus SPI2_InitForFpgaConfig()
{
  /* Init SPI */
  SPI_Handle.Init.FirstBit = SPI_FIRSTBIT_LSB;
  SPI_CLK_ENABLE();
  HAL_SPI_Init(&SPI_Handle);

  return SUCCESS;
}
예제 #20
0
파일: Panel.c 프로젝트: Sasha7b9/Osci
//------------------------------------------------------------------------------------------------------------------------------------------------------
void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef* handleSPI)
{
    if (!Panel_ProcessingCommandFromPIC(dataSPIfromPanel))
    {
        HAL_SPI_DeInit(handleSPI);
        HAL_SPI_Init(handleSPI);
    }

    SPI1->DR = Panel_NextData();
}
예제 #21
0
static void init_spi(spi_t *obj)
{
    SPI_HandleTypeDef *handle = &SpiHandle[obj->spi.module];

    __HAL_SPI_DISABLE(handle);

    HAL_SPI_Init(handle);

    __HAL_SPI_ENABLE(handle);
}
// ***** GP22 - Hardware Setup
uint8_t gp22_hw_setup()
{
  GPIO_InitTypeDef GPIO_InitStruct;
  HAL_SPI_StateTypeDef spi_status;


  // Init INT-Pin
  GPIO_InitStruct.Pin = GP22_INT_PIN;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
  HAL_GPIO_Init(GP22_INT_PORT, &GPIO_InitStruct);
  GP22_INT_CLK_ENABLE();

  // Init CS-Pin
  GPIO_InitStruct.Pin = GP22_CS_PIN;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull  = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
  HAL_GPIO_Init(GP22_CS_PORT, &GPIO_InitStruct);
  GP22_CS_CLK_ENABLE();
  GP22_CS_HIGH();

  // Init RESET-Pin
  GPIO_InitStruct.Pin = GP22_RESET_PIN;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull  = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
  HAL_GPIO_Init(GP22_RESET_PORT, &GPIO_InitStruct);
  GP22_RESET_CLK_ENABLE();
  GP22_RESET_LOW();

  // Init SPI
  hGP22_SPI.Instance = GP22_SPI;
  hGP22_SPI.Init.BaudRatePrescaler = GP22_SPI_PRESCALER;
  hGP22_SPI.Init.Direction = SPI_DIRECTION_2LINES;
  hGP22_SPI.Init.CLKPhase = SPI_PHASE_2EDGE;
  hGP22_SPI.Init.CLKPolarity = SPI_POLARITY_LOW;
  hGP22_SPI.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;
  hGP22_SPI.Init.CRCPolynomial = 7;
  hGP22_SPI.Init.DataSize = SPI_DATASIZE_8BIT;
  hGP22_SPI.Init.FirstBit = SPI_FIRSTBIT_MSB;
  hGP22_SPI.Init.NSS = SPI_NSS_SOFT;
  hGP22_SPI.Init.TIMode = SPI_TIMODE_DISABLED;
  hGP22_SPI.Init.Mode = SPI_MODE_MASTER;

  spi_status = HAL_SPI_GetState(&hGP22_SPI);
  if (spi_status != HAL_SPI_STATE_RESET)
  {
    hal_status = HAL_SPI_DeInit(&hGP22_SPI);
  }
  hal_status = HAL_SPI_Init(&hGP22_SPI);

  return hal_status;
}
예제 #23
0
void spi_abort_asynch(spi_t *obj)
{
    // diable interrupt
    vIRQ_DisableIRQ(SpiIRQs[obj->spi.module]);

    // clean-up
    SPI_HandleTypeDef *handle = &SpiHandle[obj->spi.module];
    __HAL_SPI_DISABLE(handle);
    HAL_SPI_DeInit(handle);
    HAL_SPI_Init(handle);
    __HAL_SPI_ENABLE(handle);
}
예제 #24
0
void W5500HardwareInitilize(void)
{
  __GPIOH_CLK_ENABLE();
  /*W5500 CS/INT/RST Clock enable*/
  __GPIOB_CLK_ENABLE();
  __GPIOC_CLK_ENABLE();
  
  /*W5500 GPIO&SPI1 Clock enable*/
  __GPIOA_CLK_ENABLE();
  
  /*Initialize GPIO Structure*/
  GPIO_InitTypeDef	GPIO_InitStructure;

  /*Initialize CS Pin*/
  GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
  GPIO_InitStructure.Pin = W5500_CS_PIN;
  GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStructure.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(W5500_CS_PORT,&GPIO_InitStructure);
  
  /*Initialize INT Pin*/
  GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
  GPIO_InitStructure.Pin = W5500_INT_PIN;
  GPIO_InitStructure.Mode = GPIO_MODE_INPUT;
  GPIO_InitStructure.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(W5500_INT_PORT,&GPIO_InitStructure);

  /*Ethernet shield does not have individual reset pin*/
  /* ==> Remove R23 and connect RSTN - D9 pin
        Now D9 is Reset pin.*/
  GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
  GPIO_InitStructure.Pin = W5500_RESET_PIN;
  GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStructure.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(W5500_RESET_PORT,&GPIO_InitStructure);
  
  /*SPI init*/
  hspi1W5500.Instance = W5500_SPI;
  hspi1W5500.Init.Mode = SPI_MODE_MASTER;
  hspi1W5500.Init.Direction = SPI_DIRECTION_2LINES;
  hspi1W5500.Init.DataSize = SPI_DATASIZE_8BIT;
  hspi1W5500.Init.CLKPolarity = SPI_POLARITY_HIGH;
  hspi1W5500.Init.CLKPhase = SPI_PHASE_2EDGE;
  hspi1W5500.Init.NSS = SPI_NSS_SOFT;
  hspi1W5500.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
  hspi1W5500.Init.FirstBit = SPI_FIRSTBIT_MSB;
  hspi1W5500.Init.TIMode = SPI_TIMODE_DISABLED;
  hspi1W5500.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;
  hspi1W5500.Init.CRCPolynomial = 10;
  HAL_SPI_Init(&hspi1W5500);
  
  W5500HardwareReset();
}
예제 #25
0
/*====================================================================================================*/
void MPU9250_Config( void )
{
  GPIO_InitTypeDef GPIO_InitStruct;

  /* SPI Clk ******************************************************************/
  SPIx_CS_GPIO_CLK_ENABLE();
  SPIx_SCK_GPIO_CLK_ENABLE();
  SPIx_SDO_GPIO_CLK_ENABLE();
  SPIx_SDI_GPIO_CLK_ENABLE();
  SPIx_CLK_ENABLE();

  /* SPI Pin ******************************************************************/
  GPIO_InitStruct.Mode      = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull      = GPIO_PULLUP;
  GPIO_InitStruct.Speed     = GPIO_SPEED_HIGH;

  GPIO_InitStruct.Pin       = SPIx_CS_PIN;
  HAL_GPIO_Init(SPIx_CS_GPIO_PORT, &GPIO_InitStruct);

  GPIO_InitStruct.Mode      = GPIO_MODE_AF_PP;
  GPIO_InitStruct.Pull      = GPIO_PULLUP;
  GPIO_InitStruct.Speed     = GPIO_SPEED_HIGH;

  GPIO_InitStruct.Pin       = SPIx_SCK_PIN;
  HAL_GPIO_Init(SPIx_SCK_GPIO_PORT, &GPIO_InitStruct);

  GPIO_InitStruct.Pin       = SPIx_SDO_PIN;
  HAL_GPIO_Init(SPIx_SDO_GPIO_PORT, &GPIO_InitStruct);

  GPIO_InitStruct.Pin       = SPIx_SDI_PIN;
  HAL_GPIO_Init(SPIx_SDI_GPIO_PORT, &GPIO_InitStruct);

  SPIx_CS_H;  // 低電位有效

  /* SPI Init ****************************************************************/
  SPI_HandleStruct.Instance               = SPIx;
  SPI_HandleStruct.Init.Mode              = SPI_MODE_MASTER;
  SPI_HandleStruct.Init.Direction         = SPI_DIRECTION_2LINES;
  SPI_HandleStruct.Init.DataSize          = SPI_DATASIZE_8BIT;
  SPI_HandleStruct.Init.CLKPolarity       = SPI_POLARITY_HIGH;
  SPI_HandleStruct.Init.CLKPhase          = SPI_PHASE_2EDGE;
  SPI_HandleStruct.Init.NSS               = SPI_NSS_SOFT;
  SPI_HandleStruct.Init.BaudRatePrescaler = SPIx_SPEED_LOW;
  SPI_HandleStruct.Init.FirstBit          = SPI_FIRSTBIT_MSB;
  SPI_HandleStruct.Init.TIMode            = SPI_TIMODE_DISABLE;
  SPI_HandleStruct.Init.CRCCalculation    = SPI_CRCCALCULATION_ENABLE;
  SPI_HandleStruct.Init.CRCPolynomial     = 7;
  HAL_SPI_Init(&SPI_HandleStruct);

  __HAL_SPI_ENABLE(&SPI_HandleStruct);
}
예제 #26
0
파일: Panel.c 프로젝트: Sasha7b9/Osci
//------------------------------------------------------------------------------------------------------------------------------------------------------
void Panel_Init(void)
{
#ifndef _MS_VS
    __HAL_RCC_GPIOA_CLK_ENABLE();
    __HAL_RCC_GPIOB_CLK_ENABLE();
    __SPI1_CLK_ENABLE();
#endif

    GPIO_InitTypeDef isGPIOA_B =
    {
        GPIO_PIN_5 | GPIO_PIN_6,    // GPIO_Pin
        GPIO_MODE_AF_PP,            // GPIO_Mode
        GPIO_PULLDOWN,
        GPIO_SPEED_FAST,            // GPIO_Speed
        GPIO_AF5_SPI1
    };
    HAL_GPIO_Init(GPIOA, &isGPIOA_B);
    
    isGPIOA_B.Pin = GPIO_PIN_5;
    HAL_GPIO_Init(GPIOB, &isGPIOA_B);
    
    if (HAL_SPI_Init(&handleSPI) != HAL_OK)
    {
        HARDWARE_ERROR
    }

    HAL_NVIC_SetPriority(SPI1_IRQn, PRIORITY_PANEL_SPI1);
    HAL_NVIC_EnableIRQ(SPI1_IRQn);

    // Теперь настроим программный NSS (PB6).

    GPIO_InitTypeDef isGPIOG =
    {
        GPIO_PIN_6,                 // GPIO_Pin
        GPIO_MODE_IT_RISING,        // GPIO_Mode
        GPIO_NOPULL
    };      
    HAL_GPIO_Init(GPIOB, &isGPIOG);

    HAL_NVIC_SetPriority(EXTI9_5_IRQn, PRIORITY_PANEL_EXTI9_5);
    HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);

    // Лампочка установка
    isGPIOG.Pin = GPIO_PIN_12;
    isGPIOG.Mode = GPIO_MODE_OUTPUT_PP;
    isGPIOG.Speed = GPIO_SPEED_HIGH;
    isGPIOG.Alternate = GPIO_AF0_MCO;
    HAL_GPIO_Init(GPIOG, &isGPIOG);

    Panel_EnableLEDRegSet(false);
}
예제 #27
0
void init_spi(spi_t *obj)
{
    struct spi_s *spiobj = SPI_S(obj);
    SPI_HandleTypeDef *handle = &(spiobj->handle);

    __HAL_SPI_DISABLE(handle);

    DEBUG_PRINTF("init_spi: instance=0x%8X\r\n", (int)handle->Instance);
    if (HAL_SPI_Init(handle) != HAL_OK) {
        error("Cannot initialize SPI");
    }

    __HAL_SPI_ENABLE(handle);
}
예제 #28
0
static void spi_set_speed(enum sd_speed speed)
{
	//CHECK YOUR APB1 FREQ!!!
	SPI_InitTypeDef spi;
	int prescaler = SPI_BAUDRATEPRESCALER_256;

	if (speed == SD_SPEED_400KHZ)
		prescaler = SPI_BAUDRATEPRESCALER_256;
	else if (speed == SD_SPEED_25MHZ)
		prescaler = SPI_BAUDRATEPRESCALER_4;

	FAT_SD_SPI.Init.BaudRatePrescaler = prescaler;
	HAL_SPI_Init(&FAT_SD_SPI);
}
예제 #29
0
파일: main.c 프로젝트: TomRaven/navxmxp
/* SPI1 init function */
void MX_SPI1_Init(void)
{
    hspi1.Instance = SPI1;
    hspi1.Init.Mode = SPI_MODE_SLAVE;
    hspi1.Init.Direction = SPI_DIRECTION_2LINES;
    hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
    hspi1.Init.CLKPolarity = SPI_POLARITY_HIGH;
    hspi1.Init.CLKPhase = SPI_PHASE_2EDGE;
    hspi1.Init.NSS = SPI_NSS_HARD_INPUT;
    hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
    hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
    hspi1.Init.TIMode = SPI_TIMODE_DISABLED;
    hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;
    HAL_SPI_Init(&hspi1);
}
예제 #30
0
/** 
  * @brief 
	*		SPI 2 INIT Return HAL status
	*		Config:
	*		Prescaler: 2
	*		Direction: 2 lines
	*   8 bit data
	*		Phase 1 edge
	*		Polarity LOW
	*		CRC Disabled
	*		First bit MSB
	*		NSS SOFT
  * @{
  */
uint8_t spi2_nRF_init(void){
		
		
		uint8_t spi_status = SPI_INIT_ERROR;					//Przypisanie wartosci error na poczatku
	
		__HAL_RCC_SPI2_CLK_ENABLE();									//SET CLOCK FOR SPI2
	
		gpio_init_for_spi2();													//GPIO Init for SPI
		
		gpio_nRF_init();															//GPIO Init for nRF pins like (TX_EN , TX_CE , DR)
	
		gpio_it_nRF_tx_init();												//GPIO IT init for nRF pin RD
	
		/* ==============================================================
				NOTATKI DO CONFIGURACJI SPI
				Wstepnie ustawiam na FULL Duplex master
	
				Bez sumy kontrolnej
				8 Bit danych
				Direction 2 lines
				Prescaler 64
				SPI PHASE 1 EDGE
			 ==============================================================
		*/
		spi2_init_handle.Instance 				 			= SPI2;
		spi2_init_handle.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64;  // 80MHz / 64 = 1250000 Hz
		spi2_init_handle.Init.DataSize					= SPI_DATASIZE_8BIT;
		spi2_init_handle.Init.Direction				  = SPI_DIRECTION_2LINES;	
		spi2_init_handle.Init.Mode							= SPI_MODE_MASTER;
		spi2_init_handle.Init.CLKPhase					= SPI_PHASE_1EDGE;
		spi2_init_handle.Init.CLKPolarity			  = SPI_POLARITY_LOW;
		spi2_init_handle.Init.CRCCalculation		= SPI_CRCCALCULATION_DISABLED;
		spi2_init_handle.Init.FirstBit					=	SPI_FIRSTBIT_MSB;
		spi2_init_handle.Init.NSS							  = SPI_NSS_HARD_OUTPUT;
	  spi2_init_handle.Init.TIMode 						= SPI_TIMODE_DISABLED;
		spi2_init_handle.Init.CRCPolynomial 		= 7;
		spi2_init_handle.Init.CRCLength 				= SPI_CRC_LENGTH_DATASIZE;
		spi2_init_handle.Init.NSSPMode 					= SPI_NSS_PULSE_ENABLE;
		
		spi_status = HAL_SPI_Init(&spi2_init_handle);							//INIT SPI2
							
		if(spi_status != 0){																			//IF ERROR OCURS
			usart2_WriteS("\n#ERROR IN SPI2 INIT!");
			error_function();
		}
		
		return spi_status;																				//RETURN SPI INIT STATUS
}