cancel
Showing results for 
Search instead for 
Did you mean: 

Configure SPI on stm32f205

Kolab
Senior

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Kolab
Senior

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!

View solution in original post

10 REPLIES 10
TDK
Guru

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".
Kolab
Senior

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

S.Ma
Principal

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.

Kolab
Senior

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

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

Kolab
Senior

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

S.Ma
Principal

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.

Kolab
Senior

0693W00000DmVoeQAF.pngthe program gets stuck here

S.Ma
Principal

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