AnsweredAssumed Answered

SPI fails to receive at higher speeds

Question asked by colley.elliott on Jul 17, 2015

I have a project which was originally generated using STM Cube.

I can successfully communicate to an external memory chip through SPI at 7.5MHz, although anything higher fails.  The memory chip is capable of speeds up to 25MHz, all signals are clean and have sharp rise/fall.

When operating at 15MHz, I can see the memory chip is replying as expected, however the RXNE flag is never being set after transfer (i.e. the SPI peripheral never flags that data has been received) - this doesn't make sense as the SPI receive is clocked/managed by the peripheral itself!  Any ideas or suggestions on what could be causing this, and how to resolve the issue, would be greatly appreciated.  Code snippets below.

/* SPI1 init function */
void MX_SPI1_Init(void)
  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_8;   // /8 = 7.5MHz - 4 is the desired prescaler (15MHz).  Maximum speed supported by the chip is 25MHz
  hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
  hspi1.Init.TIMode = SPI_TIMODE_DISABLED;
void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
  GPIO_InitTypeDef GPIO_InitStruct;
    /* Peripheral clock enable */
    /**SPI1 GPIO Configuration   
    PA5     ------> SPI1_SCK
    PA6     ------> SPI1_MISO
    PB5     ------> SPI1_MOSI
    GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_6;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_PULLDOWN;
    GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
    GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
    HAL_GPIO_Init(GPIOA, &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_HIGH;
    GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
void MX_SPI_RADIO_TxRx(uint8_t *txBuffer, uint8_t *rxBuffer, uint16_t len)
    HAL_StatusTypeDef result;
    result = HAL_SPI_TransmitReceive(&hspi2, txBuffer, rxBuffer, len, 10);
    if (result != HAL_OK)
        printf("? RF SPI TX/RX Error\r\n");