Spi clock not available stm32f0

I have a problem doing SPI setup on my stm32f051r8. Indeed, I wrote the hole initialization code, but I don't see the scoped clock ... I'm just trying to set up PB13 with an alternative function like a clock, but it doesn't work.

Could you help me? Many thanks.

void spi_conf()
{

GPIO_InitTypeDef    GPIO_InitStructure;
SPI_InitTypeDef   SPI_InitStructure;

/* Enable SPI clock, SPI1 */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2,ENABLE);



 /* SPI SCK, MOSI, MISO pin configuration */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_15 | GPIO_Pin_14;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_1; // 10 MHz
GPIO_Init(GPIOB, &GPIO_InitStructure);

// Configure CS pin as output floating
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOB, &GPIO_InitStructure);

GPIO_PinAFConfig(GPIOB, GPIO_PinSource13, GPIO_AF_0); // SPI1 SCK
GPIO_PinAFConfig(GPIOB, GPIO_PinSource15, GPIO_AF_0); // SPI1 MOSI
GPIO_PinAFConfig(GPIOB, GPIO_PinSource14, GPIO_AF_0); // SPI1 MISO

/* SPI configuration -------------------------------------------------------     */
SPI_I2S_DeInit(SPI2);
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;

SPI_Init(SPI2, &SPI_InitStructure);
SPI_SSOutputCmd(SPI2, ENABLE);
SPI_Cmd(SPI2, ENABLE);
}

int main(void)
{
spi_conf();

while(1)
{
}
}

      

+3


source to share


2 answers


The SCK pin is synchronized only when data is transferred via SPI. Since your code is not transmitting any data, nothing will appear on the oscilloscope.

If you want to test SPI on your board, try adding something along the lines:



SPI_I2S_SendData(SPI2, 0xA5);
delay_ms(100);

      

to your loop at the end. You should now periodically review some data.

+1


source


RCC-> APB2ENR | = RCC_APB2ENR_SPI1EN;



Place this above line of code before initializing your SPI. It will start your SPI clock.

-1


source







All Articles