STM32L476RG Full-Duplex SPI Slave Mode Configuration Issue
- February 10, 2024
- 3 replies
- 3329 views
Hi STM32 Community,
I'm working with an STM32L476RG board and attempting to set it up as a Full-Duplex SPI slave. My configuration in STM32CubeIDE seems correct, but I'm encountering an issue with receiving data. Attached are my STM32CubeIDE configuration screenshots and oscilloscope readings from the SPI master. (Master is sending out 6 bytes, "1, 2, 3, 4, 5, 6)The oscilloscope's D0, D1, and D2 channels are connected to PC3, PB10, and PB12, respectively. I believe my clock parameter settings are accurate.


The problem is that data reception is not working as expected. The HAL_SPI_RxCpltCallback function is never triggered, and consequently, an LED that should toggle within this callback remains static. Below are snippets of my STM32 code related to this issue:
1. Buffer and functions:
MX_GPIO_Init();
MX_USART2_UART_Init();
MX_SPI2_Init();
HAL_SPI_Receive(&hspi2, rxData, 6, HAL_MAX_DELAY);
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
3. SPI initialization:
static void MX_SPI2_Init(void)
{
hspi2.Instance = SPI2;
hspi2.Init.Mode = SPI_MODE_SLAVE;
hspi2.Init.Direction = SPI_DIRECTION_2LINES;
hspi2.Init.DataSize = SPI_DATASIZE_8BIT;
hspi2.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;
hspi2.Init.NSS = SPI_NSS_HARD_INPUT;
hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi2.Init.TIMode = SPI_TIMODE_DISABLE;
hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi2.Init.CRCPolynomial = 7;
hspi2.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
hspi2.Init.NSSPMode = SPI_NSS_PULSE_DISABLE;
if (HAL_SPI_Init(&hspi2) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN SPI2_Init 2 */
/* USER CODE END SPI2_Init 2 */
}
I've also attached the full code for reference. Any guidance or insights would be greatly appreciated. Thank you in advance for your help!
