AnsweredAssumed Answered

STM32F407VET6 SPI1 doesn't work PB3,PB4,PB5 and PA15

Question asked by shein.vladimir on May 25, 2013
Latest reply on May 25, 2013 by shein.vladimir

Please help. I write simple app using restricted KEIL to operate with AD5292 via SPI for my academic research project. To achive this I wrote the following code:

int main(void)
     /*!< At this stage the microcontroller clock setting is already configured to 
        168 MHz, this is done through SystemInit() function which is called from
        startup file (startup_stm32f4xx.s) before to branch to application main.
        To reconfigure the default setting of SystemInit() function, refer to
        system_stm32f4xx.c file
     GPIO_InitTypeDef GPIO_InitStruct;
     SPI_InitTypeDef spi;
     /*Enable or disable the AHB1 peripheral clock */
     RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
     RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
        RCC_APB1PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);//for SPI1
     /** SPI1 GPIO Configuration     
           PA15  ------> SPI1_NSS
           PB3      ------> SPI1_SCK
           PB4      ------> SPI1_MISO
           PB5      ------> SPI1_MOSI
     GPIO_InitStruct.GPIO_Pin = GPIO_Speed_50MHz;
     GPIO_InitStruct.GPIO_Pin = GPIO_Pin_15;
     GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
     GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
     GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
     GPIO_Init(GPIOA, &GPIO_InitStruct);
     GPIO_PinAFConfig(GPIOA, GPIO_PinSource15, GPIO_AF_SPI1);
     GPIO_InitStruct.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5;
     GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
     GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
     GPIO_Init(GPIOB, &GPIO_InitStruct);

     GPIO_PinAFConfig(GPIOB, GPIO_PinSource3, GPIO_AF_SPI1);
     GPIO_PinAFConfig(GPIOB, GPIO_PinSource4, GPIO_AF_SPI1);
     GPIO_PinAFConfig(GPIOB, GPIO_PinSource5, GPIO_AF_SPI1);

     spi.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
     spi.SPI_Mode = SPI_Mode_Master;
     spi.SPI_NSS = SPI_NSS_Soft;
     spi.SPI_CPOL = SPI_CPOL_Low; //0
     spi.SPI_CPHA = SPI_CPHA_2Edge; // 1
     spi.SPI_DataSize = SPI_DataSize_16b;
     spi.SPI_FirstBit = SPI_FirstBit_MSB;
     spi.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_64;
     SPI_SSOutputCmd(SPI1, ENABLE);
     SPI_Cmd(SPI1, ENABLE);
     SPI_NSSInternalSoftwareConfig(SPI1, SPI_NSSInternalSoft_Set);
          while(SPI_GetFlagStatus(SPI1, SPI_FLAG_TXE) == SET) 
          SPI_SendData(SPI1, 0x93);
          while(SPI_GetFlagStatus(SPI1, SPI_FLAG_BSY) == SET)

But I can't see any signaling at the pins. I tried to check if these pins weren't damaged. I wrote small app to toggle pins manually via GPIO functions. All worked fine.

Thanks for any advices.