title: STM32F4 HAL SPI_Receive dma just receive one time
body: <p>I tried many methods and read reference, but i could not correctly read data from SPI_Receive_DMA mode.</p>
  <p>In spi 1 , I want to continuously read Ad7606 data via spi in dma mode in one thread .
  However, I always received same data in SPI1 dma mode . As if i didn't receive any new data. i know that if i just want to receive data in spi dma mode ,i have to also turn on TX and RX DMA channels.
  i do not know which step i miss or wrong . Does anyone know how to solve this problem? Thanks for very much .</p>
  <pre><code>static void MX_SPI1_Init(void)
  {
    /* SPI1 parameter configuration*/
    hspi1.Instance = SPI1;
    hspi1.Init.Mode = SPI_MODE_MASTER;
    hspi1.Init.Direction = SPI_DIRECTION_2LINES;
    hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
    hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
    hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
    hspi1.Init.NSS = SPI_NSS_SOFT;
    hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
    hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
    hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
    hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
    hspi1.Init.CRCPolynomial = 10;
    if (HAL_SPI_Init(&amp;hspi1) != HAL_OK)
    {
      Error_Handler();
    }
  }
   
  static void MX_DMA_Init(void)
  {
   
    /* DMA controller clock enable */
    __HAL_RCC_DMA1_CLK_ENABLE();
    __HAL_RCC_DMA2_CLK_ENABLE();
   
    /* DMA interrupt init */
    /* DMA1_Stream4_IRQn interrupt configuration */
    HAL_NVIC_SetPriority(DMA1_Stream4_IRQn, 5, 0);
    HAL_NVIC_EnableIRQ(DMA1_Stream4_IRQn);
    /* DMA2_Stream0_IRQn interrupt configuration */
    HAL_NVIC_SetPriority(DMA2_Stream0_IRQn, 5, 0);
    HAL_NVIC_EnableIRQ(DMA2_Stream0_IRQn);
    /* DMA2_Stream3_IRQn interrupt configuration */
    HAL_NVIC_SetPriority(DMA2_Stream3_IRQn, 5, 0);
    HAL_NVIC_EnableIRQ(DMA2_Stream3_IRQn);
   
  }
  ** Note 
  DMA2_Stream0 - &gt; SPI1 Receive
  DMA2_Stream3 - &gt; SPI1 Transmit
  DMA1_Stream4 - &gt; SPI2 Transmit
  
  void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
  {
    GPIO_InitTypeDef GPIO_InitStruct = {0};
    if(hspi-&gt;Instance==SPI1)
    {
    /* USER CODE BEGIN SPI1_MspInit 0 */
   
    /* USER CODE END SPI1_MspInit 0 */
      /* Peripheral clock enable */
      __HAL_RCC_SPI1_CLK_ENABLE();
   
      __HAL_RCC_GPIOA_CLK_ENABLE();
      __HAL_RCC_GPIOB_CLK_ENABLE();
      /**SPI1 GPIO Configuration
      PA5     ------&gt; SPI1_SCK
      PA6     ------&gt; SPI1_MISO
      PB5     ------&gt; SPI1_MOSI
      */
      GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_6;
      GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
      GPIO_InitStruct.Pull = GPIO_NOPULL;
      GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
      GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
      HAL_GPIO_Init(GPIOA, &amp;GPIO_InitStruct);
   
      GPIO_InitStruct.Pin = GPIO_PIN_5;
      GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
      GPIO_InitStruct.Pull = GPIO_NOPULL;
      GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
      GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
      HAL_GPIO_Init(GPIOB, &amp;GPIO_InitStruct);
   
      /* SPI1 DMA Init */
      /* SPI1_RX Init */
      hdma_spi1_rx.Instance = DMA2_Stream0;
      hdma_spi1_rx.Init.Channel = DMA_CHANNEL_3;
      hdma_spi1_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
      hdma_spi1_rx.Init.PeriphInc = DMA_PINC_DISABLE;
      hdma_spi1_rx.Init.MemInc = DMA_MINC_ENABLE;
      hdma_spi1_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
      hdma_spi1_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
      hdma_spi1_rx.Init.Mode = DMA_NORMAL;
      hdma_spi1_rx.Init.Priority = DMA_PRIORITY_HIGH;
      hdma_spi1_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
      if (HAL_DMA_Init(&amp;hdma_spi1_rx) != HAL_OK)
      {
        Error_Handler();
      }
   
      __HAL_LINKDMA(hspi,hdmarx,hdma_spi1_rx);
   
      /* SPI1_TX Init */
      hdma_spi1_tx.Instance = DMA2_Stream3;
      hdma_spi1_tx.Init.Channel = DMA_CHANNEL_3;
      hdma_spi1_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
      hdma_spi1_tx.Init.PeriphInc = DMA_PINC_DISABLE;
      hdma_spi1_tx.Init.MemInc = DMA_MINC_ENABLE;
      hdma_spi1_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
      hdma_spi1_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
      hdma_spi1_tx.Init.Mode = DMA_NORMAL;
      hdma_spi1_tx.Init.Priority = DMA_PRIORITY_LOW;
      hdma_spi1_tx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
      if (HAL_DMA_Init(&amp;hdma_spi1_tx) != HAL_OK)
      {
        Error_Handler();
      }
   
      __HAL_LINKDMA(hspi,hdmatx,hdma_spi1_tx);
   
      /* SPI1 interrupt Init */
      HAL_NVIC_SetPriority(SPI1_IRQn, 5, 0);
      HAL_NVIC_EnableIRQ(SPI1_IRQn);
    /* USER CODE BEGIN SPI1_MspInit 1 */
   
    /* USER CODE END SPI1_MspInit 1 */
    }
  }
  
  int main(void)
  {
    HAL_Init();
    SystemClock_Config();
    MX_GPIO_Init();
    MX_DMA_Init();
    MX_SPI1_Init();
    MX_SPI2_Init();
    MX_TIM7_Init();
    MX_USART2_UART_Init();
    uint8_t receive_buffer[256] ;
    /* Init scheduler */
    osKernelInitialize();
   
   /*handle */
    SendTaskHandle = osThreadNew(SendTaskFun, NULL, &amp;SendTask_attributes);
    ReceiveTaskHandle = osThreadNew(ReceiveTaskFun, NULL, &amp;ReceiveTask_attributes);
   
    osKernelStart();
    while (1) {
    }
  }
   
   
   
  void ReceiveTaskFun(void *argument)
  {
    for (;;) {
       //-- SPI1 callback 
      HAL_SPI_RxCpltCallback(&amp;hspi1); 
      HAL_GPIO_WritePin(GPIO_A, GPIO_PIN_7, 1); //-- cs=1    deactive 
  }
   
   
   
  void DMA2_Stream0_IRQHandler(void)
  {
    HAL_DMA_IRQHandler(&amp;hdma_spi1_rx);
  }
   
  void DMA2_Stream3_IRQHandler(void)
  {
    HAL_DMA_IRQHandler(&amp;hdma_spi1_tx);
  }
   
   
  void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi)
  {
     if (hspi-&gt;Instance == SPI1){
           //-- Enable CS
           HAL_GPIO_WritePin(GPIO_A, GPIO_PIN_7, 0); //-- cs=0   active low  
  
           //- -  SPI2_DMA_receive
           ...... (Here is for receive data from AD7606 )
       HAL_SPI_Receive_DMA(&amp;hspi1, receive_buffer, 8);
     }
  }
  
  
  
  
   
  </code></pre>