AnsweredAssumed Answered

STM32VLDiscovery SPI2 - how to enable?

Question asked by watts.dan.001 on Jun 3, 2014
Latest reply on Jun 3, 2014 by watts.dan.001
Hi,

I'm new to STM32 development.  I'm working my way through Professor Geoffrey Brown's "Discovering the STM32 Microcontroller", using an STM32VL Discovery board, and have run into a snag in the SPI section.

After not getting SPI2 to work at all, with various examples I have tried.  The same examples work when I use SPI1. 

I'm wondering if the problem is with my code to enable the clock for SPI2.

Here's the relevant section of my SPI initialization code, with the SPI2 clock enabling code highlighted...

if (SPIx == SPI1)
{
    // A5 = SCK, , A7 = MOSI


    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_SPI1, ENABLE);
    GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_5 | GPIO_Pin_7;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF_PP;
    GPIO_Init(GPIOA, &GPIO_InitStructure);
    
    // A6 = MISO
    GPIO_StructInit(&GPIO_InitStructure);
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
    GPIO_Init(GPIOA, &GPIO_InitStructure);


} else  if (SPIx == SPI2) {
    // B13 = SCK, B15 = MOSI
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB1Periph_SPI2, ENABLE);
    GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_13 | GPIO_Pin_15;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF_PP;
    GPIO_Init(GPIOB, &GPIO_InitStructure);
    
    // B14 = MISO
    GPIO_StructInit(&GPIO_InitStructure);
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
    GPIO_Init(GPIOB, &GPIO_InitStructure);
}


Does that look correct?  If so, are there any special considerations when using SPI2 on the STM32VL Discovery board -- extra steps that aren't required when using SPI1?

Thanks,

Dan

Outcomes