2019-07-17 06:51 AM
Hello
i configured the spi interface as follows (8 bit data size):
static void MX_SPI1_Init(void)
{
/* SPI1 parameter configuration*/
hspi1.Instance = SPI1;
hspi1.Init.Mode = SPI_MODE_MASTER;
hspi1.Init.Direction = SPI_DIRECTION_2LINES_RXONLY;
hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi1.Init.CLKPhase = SPI_PHASE_2EDGE;
hspi1.Init.NSS = SPI_NSS_SOFT;
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_128;
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi1.Init.CRCPolynomial = 7;
hspi1.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
hspi1.Init.NSSPMode = SPI_NSS_PULSE_DISABLE;
if (HAL_SPI_Init(&hspi1) != HAL_OK)
{
Error_Handler();
}
}
when i execute the command to read 2 x 8bit:
HAL_SPI_Receive(&hspi1, spiRxData, 2, 1)
why do the SPI_SCK output generates 24 clocks instead of 16?
(10 bit data size, 30 instead of 20 and so on)
Is there a logical explanation for this?
Best regards
Stefan
2019-07-17 07:41 AM
> hspi1.Init.Direction = SPI_DIRECTION_2LINES_RXONLY;
In Rx-Only Master, SPI outputs clocks as soon as SPIx_CR1.SPE=1 and stops only when SPIx_CR1.SPE=0. Cube/HAL has no mechanism for precision stop. You are better off using the usual fullduplex mode, you don't need to enable MOSI in GPIO.
JW