2016-04-20 06:09 AM
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 structRCC_OscInitTypeDef which is not present in STM32F2.
Can you help me to set STM32F2 clocks?
THANKS
2016-04-21 07:00 AM
Hi,
You can find a full set of running examples within the STM32CubeF2 firmware package that can help you in SPI configuration and get inspiration to achieve your goal.From this path: STM32Cube_FW_F2_V1.3.0\Projects\STM322xG_EVAL\Examples\SPIRegards2016-04-22 01:45 AM
THANK YOU!!!