AnsweredAssumed Answered

SPI1 on STM32F4Discovery

Question asked by debegr on Jun 2, 2013
Latest reply on Jun 3, 2013 by waclawek.jan
Hi community,
for a few days i try to use the SPI1 on the F4Discovery board. I use the PA5-PA7 pins on AF5. But after my init the code does nothing? What is wrong in my init function?

#define Open_SPI_MISO_PIN                GPIO_Pin_6
#define Open_SPI_MOSI_PIN                GPIO_Pin_7
#define Open_SPI_SCK_PIN                GPIO_Pin_5

#define Open_SPI_GPIO_PORT                GPIOA
#define Open_SPI_GPIO_CLK                RCC_AHB1Periph_GPIOA
#define Open_SPI_CLK                    RCC_APB2Periph_SPI1

#define Open_SPI_MISO_SOURCE            GPIO_PinSource6
#define Open_SPI_MOSI_SOURCE            GPIO_PinSource7
#define Open_SPI_SCK_SOURCE                GPIO_PinSource5

#define Open_SPI_MISO_AF                GPIO_AF_SPI1
#define Open_SPI_MOSI_AF                GPIO_AF_SPI1
#define Open_SPI_SCK_AF                    GPIO_AF_SPI1

#define Open_SPI_MISO_GPIO_PORT            GPIOA
#define Open_SPI_MOSI_GPIO_PORT            GPIOA
#define Open_SPI_SCK_GPIO_PORT            GPIOA

#define Open_SPI                        SPI1


void SPI_BusInit(void)
{
    GPIO_InitTypeDef GPIO_InitStructure;
    SPI_InitTypeDef  SPI_InitStructure;
    //NVIC_InitTypeDef NVIC_InitStructure;

    //=========================================================================================
    // Enable GPIO clock
    //-----------------------------------------------------------------------------------------
    RCC_AHB1PeriphClockCmd(Open_SPI_GPIO_CLK, ENABLE);

    //=========================================================================================
    // Enable SPI clock
    //-----------------------------------------------------------------------------------------
    RCC_APB2PeriphClockCmd(Open_SPI_CLK, ENABLE);

    //=========================================================================================
    // Configure SPI GPIO
    //-----------------------------------------------------------------------------------------
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStructure.GPIO_Pin = Open_SPI_MISO_PIN | Open_SPI_MOSI_PIN | Open_SPI_SCK_PIN;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(Open_SPI_GPIO_PORT, &GPIO_InitStructure);

    //=========================================================================================
    //GPIO Alternate functions configuration
    //-----------------------------------------------------------------------------------------
    GPIO_PinAFConfig(Open_SPI_MISO_GPIO_PORT, Open_SPI_MISO_SOURCE, Open_SPI_MISO_AF);
    GPIO_PinAFConfig(Open_SPI_MOSI_GPIO_PORT, Open_SPI_MOSI_SOURCE, Open_SPI_MOSI_AF);
    GPIO_PinAFConfig(Open_SPI_SCK_GPIO_PORT, Open_SPI_SCK_SOURCE, Open_SPI_SCK_AF);

    //=========================================================================================
    // Configure SPI AF
    //-----------------------------------------------------------------------------------------
    //SPI_I2S_DeInit(SPI1);
    SPI_StructInit(&SPI_InitStructure);
    SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_32;    // 328kHz
    //SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
    //SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
    //SPI_InitStructure.SPI_CRCPolynomial = 7;
    SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
    SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
    SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
    SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
    SPI_InitStructure.SPI_NSS = SPI_NSS_Soft | SPI_NSSInternalSoft_Set;

    SPI_Init(Open_SPI, &SPI_InitStructure);
    //SPI_CalculateCRC(Open_SPI, DISABLE);
    SPI_Cmd(Open_SPI, ENABLE);

Outcomes