Skip to main content
SThir.4
Associate
May 13, 2021
Solved

Dual SPI with DMA

  • May 13, 2021
  • 2 replies
  • 958 views

Hello everyone,

I'm using the STM32H743 and I would like to implement two SPI communications with DMA (SPI1 & SPI2). I followed the example provided with my Nucleo board which is working perfectly when I'm only using SPI1 but when I add SPI2 initialisation (by copying and modifying the code for SPI2), SPI1 does not work anymore (SPI2 never worked yet).

It seems that is coming from the initalisation of the DMA with SPI2 because when I remove that part, SPI1 is working as expected.

Before focusing on that issue, I have a little question about the initialisation.

In the example code, the initialisation is done in a similar way in the main :

 SpiHandle.Instance = SPI1;
 SpiHandle.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_256;

Can this code be replaced by something like this ?

void SPI_Init(SPI_HandleTypeDef *hspi)
{
 if (hspi->Instance == SPI1)			// SPI1
 {
		hspi->Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_256;

and called in the main like this ?

SpiHandle.Instance = SPI1;
SPI_Init(&SpiHandle);

I prefer the second way and even if it seems to work, I don't know if it's the best way or if it's recommended.

Thank you for your help.

To avoid too much questions in a row, I wanted to focus on the initialisation first :smiling_face_with_halo:

This topic has been closed for replies.
Best answer by waclawek.jan

You need a separate handle for each SPI (i.e. you cannot recycle the SpiHandle variable).

JW

2 replies

waclawek.jan
waclawek.janBest answer
Super User
May 13, 2021

You need a separate handle for each SPI (i.e. you cannot recycle the SpiHandle variable).

JW

SThir.4
SThir.4Author
Associate
May 14, 2021

Thank you very much Jan !

It's working as expected now