cancel
Showing results for 
Search instead for 
Did you mean: 

Dual SPI with DMA

SThir.4
Associate II

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:

1 ACCEPTED SOLUTION

Accepted Solutions

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

JW

View solution in original post

2 REPLIES 2

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

JW

SThir.4
Associate II

Thank you very much Jan !

It's working as expected now