AnsweredAssumed Answered

STM32F405 - No clock on SPI

Question asked by fontaine.aurelie on Oct 14, 2013
Latest reply on Oct 14, 2013 by John F.
Hello,
I've some problems with the SPI interface of the STM32F405 microcontroller. I hope someone could help me.

I've a F-RAM connected to the STM32F405 via SPI. I'll checked pin connection and GPIO configuration with an oscilloscope ( set/reset IO), all works.
But I'm not able to receive or transmit data with SPI interface. There is no clock generating on the Clock pin (PC10).

To my code :

    GPIO_InitTypeDef GPIO_InitStructure;
    SPI_InitTypeDef  SPI_InitStructure;
    
    SPI_I2S_DeInit( SPI3);
    
        /* Enable GPIO and SPI Periph Clock */
    RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOA, ENABLE );
    RCC_APB1PeriphClockCmd( RCC_APB1Periph_SPI3, ENABLE );
    
    /* Connect CLK, MISO, MOSI and CS on AF6 */
    GPIO_PinAFConfig( GPIOC, GPIO_Pin_10, GPIO_AF_SPI3 );
    GPIO_PinAFConfig( GPIOC, GPIO_Pin_11, GPIO_AF_SPI3 );
    GPIO_PinAFConfig( GPIOC, GPIO_Pin_12, GPIO_AF_SPI3 );
    GPIO_PinAFConfig( GPIOA, GPIO_Pin_4, GPIO_AF_SPI3 );
    
    /* Configure SPI pins: ---------------------------------------------------*/
    /* Configure SCK MISO and MOSI pins as Alternate Function Push Pull */
    GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_10| GPIO_Pin_11| GPIO_Pin_12;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF;
    GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_NOPULL;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_Init( GPIOC, &GPIO_InitStructure );
    
    /* Configure CS pin  */
    GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_4;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
    GPIO_Init( GPIOA, &GPIO_InitStructure ); 
    GPIO_SetBits( GPIOA, GPIO_Pin_4);
    
    /* Configure Write Protection pin (active low) */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
    GPIO_Init( GPIOB, &GPIO_InitStructure ); 
    GPIO_SetBits( GPIOB, GPIO_Pin_0);
    
    /* SPI Configuration -----------------------------------------------------*/
    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_256;      
    SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
    SPI_Init( SPI3, &SPI_InitStructure ); 
    
    /* TEST */
     /* Enable the SPI peripheral */
    SPI_Cmd( SPI3, ENABLE );
    /* Enable CS (active low) */
     GPIO_ResetBits( GPIOA, GPIO_Pin_4);
    while( 1 )
    {
        SPI_I2S_SendData( SPI3, 0xAA );
    }

Thanks & Best regards,
Aurélie.

Outcomes