2014-06-02 04:32 PM
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 = MOSIRCC_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 #stm32-stm32vldiscovery-stm32f1002014-06-02 07:08 PM
SPI1 and SPI2 are on different APB
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);2014-06-03 08:06 AM