AnsweredAssumed Answered

STM32F2 SPI

Question asked by marchetti.simone on Apr 20, 2016
Latest reply on Apr 22, 2016 by marchetti.simone
Hi,
I need to "translate" a SPI program written for STM32F4 to STM32F2. 
I wrote SPI configuration:
//STM32F4
 
void MX_SPI1_Init(void)
{
 
  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_2;
  hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
  hspi1.Init.TIMode = SPI_TIMODE_DISABLED;
  hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;
  HAL_SPI_Init(&hspi1);
 
}

and 
//STM32F2
// enable peripheral clock
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);
    SPI_InitStructure.SPI_Mode = SPI_Mode_Master;     // transmit in master mode, NSS pin has to be always high
    SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; // set to full duplex mode, seperate MOSI and MISO lines
    SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; // one packet of data is 8 bits wide
    SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;        // clock is low when idle
    SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;      // data sampled at first edge
    SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
    SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4; // SPI frequency is APB2 frequency / 4
    SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;// data is transmitted MSB first
 
     
    SPI_Init(SPI1, &SPI_InitStructure);
    SPI_TIModeCmd(SPI1, DISABLE);
    SPI_CalculateCRC(SPI1, DISABLE);
    SPI_Cmd(SPI1, ENABLE); // enable SPI1

I have problems with clocks settings.
There is this source code in STM32F4:
   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.HSICalibrationValue = 6;
  HAL_RCC_OscConfig(&RCC_OscInitStruct);
This code set the struct RCC_OscInitTypeDef which is not present in STM32F2.
Can you help me to set STM32F2 clocks?
THANKS

Outcomes