Data is being sampled by SPI even if clock signal is not provided, when configured as slave.
Below is the SPI register configuration:
CR1 Register
Register Bit parameter
Config value
Description
BIDIMODE
0
2-line unidirectional data mode
BIDIOE
0
Receive-only mode
CRCEN
0
CRC calculation disabled
CRCNEXT
0
Next transmit value is from TX buffer
CRCL
0
8-bit CRC length
RXONLY
1
Output disabled (Receive-only mode)
SSM
1
Software slave management enabled
SSI
0
LSBFIRST
0
data is received with the MSB first
SPE
1
Peripheral enabled
BR[2:0]
0
fPCLK/2
MSTR
0
Slave mode
CPOL
1
CK to 1 when idle
CPHA
1
The second clock transition is the first data capture edge
CR2 Register
Register Bit parameter
Config value
Description
DS [3:0]:
0x07
8 - bits data length for SPI transfers
Are we missing any configurations ? Could you please guide us to resolve this issue ?
Below is the SPI & GPIO initialization code:
[NOTE : The function HAL_SPI_MspInit() is getting invoked inside the HAL_SPI_Init() ]
SPI_HandleTypeDef stSpiHandle = { 0 }; // SPI handler declaration
void SPIInit( void )
{ /* Set the SPI parameters */ stSpiHandle.Instance = SPI1;stSpiHandle.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
stSpiHandle.Init.Direction = SPI_DIRECTION_2LINES_RXONLY; stSpiHandle.Init.CLKPhase = SPI_PHASE_2EDGE; stSpiHandle.Init.CLKPolarity = SPI_POLARITY_HIGH; stSpiHandle.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; stSpiHandle.Init.DataSize = SPI_DATASIZE_8BIT; stSpiHandle.Init.FirstBit = SPI_FIRSTBIT_MSB; stSpiHandle.Init.NSS = SPI_NSS_SOFT; stSpiHandle.Init.NSSPMode = SPI_NSS_PULSE_DISABLE; stSpiHandle.Init.TIMode = SPI_TIMODE_DISABLE; stSpiHandle.Init.Mode = SPI_MODE_SLAVE;if ( HAL_SPI_Init( &stSpiHandle ) != HAL_OK )
{ SET_FAULT_STATUS( FAULT_SPI_CONFIG_FAILED ); }}void HAL_SPI_MspInit(SPI_HandleTypeDef *hspi)
{ GPIO_InitTypeDef GPIO_InitStruct;if(hspi->Instance == SPI1)
{ /* Enable peripherals and GPIO Clocks */ SPI1_SCK_GPIO_CLK_ENABLE(); SPI1_MOSI_GPIO_CLK_ENABLE(); SPI1_CLK_ENABLE();/* SPI SCK GPIO pin configuration */
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Pin = SPI1_SCK_PIN; GPIO_InitStruct.Alternate = SPI1_SCK_AF; HAL_GPIO_Init(SPI1_SCK_GPIO_PORT, &GPIO_InitStruct);/* SPI MOSI GPIO pin configuration */
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Pin = SPI1_MOSI_PIN; GPIO_InitStruct.Alternate = SPI1_MOSI_AF; HAL_GPIO_Init(SPI1_MOSI_GPIO_PORT, &GPIO_InitStruct); }}Thanks & Regards,
Kishor
#stm32f030-spi-clock #stm32f0-spi #spi