cancel
Showing results for 
Search instead for 
Did you mean: 

SPI doesn't stop clock after transmission completed.

Roman
Associate II

Hi!

Have a problem with SPI.

SPI configured as SSI master RX only, and for the first transmission SPI generates additional clock cycle for one more word. What can be cause of such behavior? But it's work fine with less frequency (125 Khz)

Here is initialization:

   /* SPI1 parameter configuration*/

   hspi2.Instance = SPI2;

   hspi2.Init.Mode = SPI_MODE_MASTER;

   hspi2.Init.Direction = SPI_DIRECTION_2LINES_RXONLY;

   hspi2.Init.DataSize = SPI_DATASIZE_16BIT;

   hspi2.Init.CLKPolarity = SPI_POLARITY_HIGH;

   hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;

   hspi2.Init.NSS = SPI_NSS_SOFT;

   hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32;      // 1 Mhz

   hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;

   hspi2.Init.TIMode = SPI_TIMODE_DISABLE;

   hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;

   hspi2.Init.CRCPolynomial = 10;

This is transition function:

HAL_SPI_Receive_IT(&hspi2, (uint8_t *)dig_buf, 2); // start receive interrupt

where dig_buf is uint16_t, i tried with uint8_t variables but it is the same result for the first transition.

3 REPLIES 3
Roman
Associate II

So, there is a problem with this configuration SPI_DIRECTION_2LINES_RXONLY, with SPI_DIRECTION_2LINES works fine. It's strange behavior, if anyone has explanations to this it would be great.

This is documented in the RM, if you care to read the description of Rx-only mode in the SPI chapter.

As you've found out, if you don't need bidirectional support, you can use the normal duplex mode, you don't need to assign MOSI pin in GPIO.

JW

Ok, thank you for your answer, I'll keep it in mind!