cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F446 SPI SLAVE IN DMA RECEIVES DATA BUT DOES NOT TRANSMIT

james farrant
Associate II

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

1 ACCEPTED SOLUTION

Accepted Solutions

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

View solution in original post

5 REPLIES 5
AScha.3
Chief III

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 ?

If you feel a post has answered your question, please click "Accept as Solution".

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 */
  }
 
}

 

>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.)

If you feel a post has answered your question, please click "Accept as Solution".

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

Yes it definitely is the right pin.

its an STM32F446 - LQFP64

PA4 - PA7, pins 20 - 23

MISO is pin 22 which corresponds to PA6 in data sheet and my schematic. Everything is hooked up and configured correctly. 

This is a custom board I assembled on a hot plate with a stencil. There were multiple solder bridges that had to be fixed. Not really sure but definitely pointing to the IC at this point.