Skip to main content
Visitor II
October 19, 2024
Solved

STM32F446 SPI SLAVE IN DMA RECEIVES DATA BUT DOES NOT TRANSMIT

  • October 19, 2024
  • 1 reply
  • 1809 views

I have a Beaglebone Computer configured as SPI Masted, and an STM32F446 configured as SPI Slave. I am simply sending 'HelloWorld' from the Beaglebone to the STM32, and trying to send 'ABCDEFG!' from the STM32 to the Beaglebone. The STM32 receives the message from the Beaglebone as expected, but the STM32 MISO line never outputs the message to the Beaglebone. 

See the image for reference which shows the MISO output from the STM in blue, clk in yellow, and MOSI in green. 

I am using HAL_SPI_TransmitReceive_DMA(&hspi1, SPITxByte, SPIRxByte, SPI_BUFF_LEN); for setting up the communication.

Can someone please help me out here? I've been scratching my head for days. 

Attached is my Cube Generated main.c file

    This topic has been closed for replies.
    Best answer by james farrant

    Well, looks like this is a hardware issue. I Tried the same code on a Nucleo dev kit and it works as expected. 

    1 reply

    Super User
    October 19, 2024

    Check : you have connected to the pin as set/given in Cube ; and check : is it really connected to stm pin ?

    Because the blue signal looks like an open line , just some stray in from other lines.

    + pin speed setting high enough for your spi speed ?

    Visitor II
    October 19, 2024

    I have been able to read continuity from the MISO header pin to the MCU package pin so I know that is good.

    I will attempt running this code on a nucleo dev kit to verify. 

    Here is the cube generated HAL_SPI_MspInit functio that shows the correct initialization of the SPI peripherals.

     

    void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
    {
      GPIO_InitTypeDef GPIO_InitStruct = {0};
      if(hspi->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();
        /**SPI1 GPIO Configuration
        PA4     ------> SPI1_NSS
        PA5     ------> SPI1_SCK
        PA6     ------> SPI1_MISO
        PA7     ------> SPI1_MOSI
        */
        GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7;
        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, &GPIO_InitStruct);
     
        /* 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(&hdma_spi1_tx) != HAL_OK)
       {
    Error_Handler();
       }
     
       __HAL_LINKDMA(hspi,hdmatx,hdma_spi1_tx);
     
        /* 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_CIRCULAR;
        hdma_spi1_rx.Init.Priority = DMA_PRIORITY_LOW;
        hdma_spi1_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
        if (HAL_DMA_Init(&hdma_spi1_rx) != HAL_OK)
        {
          Error_Handler();
        }
     
        __HAL_LINKDMA(hspi,hdmarx,hdma_spi1_rx);
     
     
        /* SPI1 interrupt Init */
        //HAL_NVIC_SetPriority(SPI1_IRQn, 0, 0);
        //HAL_NVIC_EnableIRQ(SPI1_IRQn);
      /* USER CODE BEGIN SPI1_MspInit 1 */
     
      /* USER CODE END SPI1_MspInit 1 */
      }
     
    }

     

    Super User
    October 19, 2024

    >from the MISO header pin to the MCU package pin

    Ok, but is it really same pin, you set in Cube for this miso ? (that was my question - also.)