AnsweredAssumed Answered

SPI transmit problem

Question asked by domi.z on Jun 22, 2015
Latest reply on Jun 26, 2015 by chahrayar.chahrazed
I am using a STM32F103RBT6 and I'm trying to use SPI in slave fullduplex mode with generated code from CubeMX.
The master is sending a predefined data package and I try to respond.

I can receive the whole data package correctly, if I'm not sending anything back during the data transfer.
As soon as I begin to answer (I answer each byte), I can receive two byte, but after that the received data begins to make no sense.
It looks like sending something is interfering with receiving further data.

I tried using DMA or interrupt for transmit and receive, but I had the same issue.

I'm guessing that there is somehow a problem with my initialization of the SPI module, but I can't see where and I'm only using the generated CubeMX code

/* SPI1 init function */
void MX_SPI1_Init(void)
{
 
    hspi1.Instance = SPI1;
    hspi1.Init.Mode = SPI_MODE_SLAVE;
    hspi1.Init.Direction = SPI_DIRECTION_2LINES;
    hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
    hspi1.Init.CLKPolarity = SPI_POLARITY_HIGH;
    hspi1.Init.CLKPhase = SPI_PHASE_2EDGE;
    hspi1.Init.NSS = SPI_NSS_SOFT;
    hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_256;
    hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
    hspi1.Init.TIMode = SPI_TIMODE_DISABLED;
    hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;
    hspi1.Init.CRCPolynomial = 7;
    HAL_SPI_Init(&hspi1);
 
}

Outcomes