cancel
Showing results for 
Search instead for 
Did you mean: 

Using timer to trigered SPI DMA Rx could not be received data

armco
Associate II

I want to share my related code and photo here. The program runs on an STM32F746 Nucleo Board.  It uses timer 2 to trigger DMA1 stream 0 causing fixed-length transmission of data via SPI 1 to an external ADC without interrupts on the transmission side. Timer 2 confüguration is settled at 25600Hz this is used as a sample rate. Therefore data must be received with SPI3 every 25600Hz. I created a test pin to understand that the sampling process is finished. The sample size is 64. The complete time is  64 x 1/25600 = 400Hz. I can see this period with diligent oscilloscope but the received data is empty. Can you show me where I'm doing wrong?

Code:

 

SPI_HandleTypeDef hspi3;
DMA_HandleTypeDef hdma_spi3_rx;

TIM_HandleTypeDef htim2;

DMA_HandleTypeDef hdma_tim2_up_ch4;

#define fs (25600)
#define RX_BUFFER_LENGTH (64)

memset(rxBuffer, 0, sizeof(rxBuffer));
txBuffer = 0xFFFF;

// Start SPI RX DMA
hspi3.hdmarx->XferCpltCallback = mySPI_DMAReceiveCplt;
SET_BIT(hspi3.Instance->CR2, SPI_RXFIFO_THRESHOLD);
HAL_GPIO_WritePin(ADC_CS_Pin_GPIO_Port, ADC_CS_Pin_Pin, RESET);
HAL_DMA_Start_IT(hspi3.hdmarx, (uint32_t)&hspi3.Instance->DR, (uint32_t)rxBuffer, RX_BUFFER_LENGTH);
SET_BIT(hspi3.Instance->CR2, SPI_CR2_RXDMAEN);
__HAL_SPI_ENABLE(&hspi3);


// Prepare TIM DMA to SPI_DR

HAL_DMA_Start(htim2.hdma[TIM_DMA_ID_UPDATE], (uint32_t)&txBuffer, (uint32_t)&hspi3.Instance->DR, 1);
__HAL_TIM_ENABLE_DMA(&htim2, TIM_DMA_UPDATE);

// Start the timer
__HAL_TIM_ENABLE(&htim2);

while (1)
{

}

 

static void mySPI_DMAReceiveCplt(DMA_HandleTypeDef *hdma)
{
 
if( hdma == &hdma_spi3_rx )
{
    HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_6);    // IO test pin
}
}
 
WhatsApp Image 2023-10-03 at 14.29.26.jpegWhatsApp Image 2023-10-03 at 14.29.27.jpeg
10 REPLIES 10

As this is Cortex-M7, also watch out for the caching issues.


Not only they don't read manuals, but, of course, they also ignore most of what is told them individually...

Also, how about:

  1. Posting a code as a proper code block.
  2. Posting long pieces of code as an attached file.
  3. Posting a screenshots as an actual screenshots instead of a "photographed monitor" images.