cancel
Showing results for 
Search instead for 
Did you mean: 

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

sheinv
Associate II
Posted on May 25, 2013 at 00:54

Hi.

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_StructInit(&GPIO_InitStruct);

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_DeInit(SPI1);

SPI_StructInit(&spi);

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_Init(SPI1,&spi);

SPI_CalculateCRC(SPI1,DISABLE);

SPI_SSOutputCmd(SPI1, ENABLE);

SPI_Cmd(SPI1, ENABLE);

SPI_NSSInternalSoftwareConfig(SPI1, SPI_NSSInternalSoft_Set);

while(1)

{

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.

#stm32f407vet6-spi1-pb3-pb4-pb5
3 REPLIES 3
Posted on May 25, 2013 at 01:27

RCC_APB1PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);//for SPI1

APB2 APB2 ...
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
sheinv
Associate II
Posted on May 25, 2013 at 09:56

Many thanks clive1 for your attention to my problem.

It was my mistake and if to say more precisely this was my misspell 🙂 I tried many other variants before but without any success. :(

I corrected ABP1 with ABP2 but I still can't see any signaling at the pins. And only when I switched the mode of the pins to GPIO and wrote the code to toggle states of the pins I can see meander at them.

How do you think where can be the source of the problem?

Thanks for your correction and help.

sheinv
Associate II
Posted on May 25, 2013 at 10:40

Thanks a lot, clive1!

The second problem was at the following line:

while(SPI_GetFlagStatus(SPI1, SPI_FLAG_TXE) == SET)

the line should be

while(SPI_GetFlagStatus(SPI1, SPI_FLAG_TXE) == RESET)

Now everything is Ok.

Many many thanks!