Skip to main content
August 31, 2021
Solved

Configure SPI on stm32f205

Hello!

How can I configure only the MISO pin in the mode falling edge triggered interrupt input? It's not possible to do it on CubeMX. I tried to change the spi.c file like follows:

/**SPI3 GPIO Configuration

  PA15   ------> SPI3_NSS

  PC10   ------> SPI3_SCK

  PC11   ------> SPI3_MISO

  PC12   ------> SPI3_MOSI

  */

  GPIO_InitStruct.Pin = GPIO_PIN_15;

  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

  GPIO_InitStruct.Pull = GPIO_NOPULL;

  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;

  GPIO_InitStruct.Alternate = GPIO_AF6_SPI3;

  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12;

GPIO_InitStruct.Mode = I replaced GPIO_MODE_AF_PP; by GPIO_MODE_AF_PP|GPIO_MODE_IT_FALLING|GPIO_MODE_AF_PP;

  GPIO_InitStruct.Pull = GPIO_NOPULL;

  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;

  GPIO_InitStruct.Alternate = GPIO_AF6_SPI3;

  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

But it doesn't work. Any help, please?

This topic has been closed for replies.
Best answer
September 27, 2021

thank you all for your help so far. I realized that only setting on Cube a pin as Alternate Function Push Pull is enough to allow you to use this pin as falling edge triggered interrupt input (as this was need for the ADC ads1118). The problem was actually with the spi3 configuration on Cube: I misconfigured the CPAH. This was the key to solve the issue!

10 replies

TDK
August 31, 2021

I don't think it's possible within the HAL framework. But you can do it by editing registers directly.

"If you feel a post has answered your question, please click ""Accept as Solution""."
September 1, 2021

I got your point. And could you give an example for my case, how it should be done?

S.Ma
Principal
September 5, 2021

I suggest to configure the Exti interrupt for miso and spi without miso in cube mx, then, after mx init, manually reactivate miso as spi alternate signal. Hack will work. EXTI on alternate function pin works fine even if the HAL didn't foresaw users needing this confuguration and CubeMX based apparently on HAL and not the reference manual.

September 5, 2021

Hello @S.Ma​  let me see if I got you point: you mean activate SPI on CubeMX, then change the MISO pin configuration to GPIO_EXTIx, then after MX init change manually back MISO pin configuration to alternate function?

S.Ma
Principal
September 5, 2021

You got it, CubeMX is a static HW configuration, you can override it manually.

September 7, 2021

@S.Ma​  can I just reconfigure it inside the functions HAL_SPI_MspInit and HAL_SPI_MspDeInit ?

S.Ma
Principal
September 8, 2021

Well, run your code with debugger and check if your code insertion work by looking at the gpio and exti registere.... not specialist of hal intricacies.

September 8, 2021

0693W00000DmVoeQAF.pngthe program gets stuck here

S.Ma
Principal
September 27, 2021

Did you create the exti interrupt handler function? If this looks difficult to you, get a files compare text viewer, generate a simple concisr project for spi and exti, look at both anf try to merge. Exti and spi are decorrelated function. You decide when each one has to be enabled

Best answer
September 27, 2021

thank you all for your help so far. I realized that only setting on Cube a pin as Alternate Function Push Pull is enough to allow you to use this pin as falling edge triggered interrupt input (as this was need for the ADC ads1118). The problem was actually with the spi3 configuration on Cube: I misconfigured the CPAH. This was the key to solve the issue!