cancel
Showing results for 
Search instead for 
Did you mean: 

SPI example on Nucleo-g474

LHarm.1
Associate III

I'm using a Nucleo-g474RE

I want to use a timer / DMA to trigger a SPI Rx only transfer to memory.

I need to transfer two 9 bit words every trigger, 1 uSecs, and 4096 two word transfers

Can anyone point me to an MX cube example?

3 REPLIES 3

Whatever you do, avoid Rx only with SPI.

JW

FBL
ST Employee

Hello @LHarm.1​, 

You can get started with this example. You need to consider reconfiguring SPI, DMA to perform a receive only continuous SPI transfer each timer trigger. Also, you add and set up the timer then request channel for DMA. Here is an example to start SPI then prepare TIM DMA to SPI

/* Start SPI RX DMA */
  SET_BIT(hspi1.Instance->CR2, SPI_RXFIFO_THRESHOLD);
  HAL_DMA_Start_IT(hspi1.hdmarx, (uint32_t)&hspi1.Instance->DR, (uint32_t)rxBuffer, RX_BUFFER_LENGTH);
  SET_BIT(hspi1.Instance->CR2, SPI_CR2_RXDMAEN);
  __HAL_SPI_ENABLE(&hspi1);
 
  /* Prepare TIM DMA to SPI_DR */
  HAL_DMA_Start(htim1.hdma[TIM_DMA_ID_UPDATE], (uint32_t)&txBuffer, (uint32_t)&hspi1.Instance->DR, 1);
  __HAL_TIM_ENABLE_DMA(&htim1, TIM_DMA_UPDATE);
 
  /* Start the timer */
  __HAL_TIM_ENABLE(&htim1);

Later some modifications are necessary to synchronize SPI and Timer. Otherwise, you can use a capture compare Timer. For further details about data transmission using DMA check the reference manual section 39.5.9 Data transmission and reception procedures and the subsection Communication using DMA.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

LHarm.1
Associate III

Thanks, I'll take a look.