SPI slave doesn't receive information from SPI master in STM32h7
I want to send data from one SPI master to an SPI slave in the same MCU. I don't have separated bards for master and slave, they are in the same board. I'm using an STM32H7 MCU with the following configuration:
SPI master:
SPI slave:
With the following pins:
- Master
- MISO: PA6
- MOSI: PD7
- SCK: PA5
- NSS (by SW): PC7
- Slave
- MISO: PB4
- MOSI: PB5
- SCK: PB3
- NSS: PA4
I have connected wired the pins as following, by looking at the provided table:
In order to have both SPI master and slave in the same board, I have needed to use PD7 for the SPI master, which is described as an USART pin in the following table, but I'm not using the USART so I can use it for SPI.


And here is my source code (I will provide only my custom code, not the one generated by CubeMX):
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_SPI1_Init();
MX_SPI3_Init();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
uint8_t buf[8] = {0x55, 2, 3, 4, 5, 6, 7, 8};
uint8_t recv = 0;
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_7, GPIO_PIN_SET);
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_7, GPIO_PIN_RESET);
HAL_SPI_Transmit(&hspi1, (void*)buf, 1, 1000);
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_7, GPIO_PIN_SET);
HAL_StatusTypeDef rc = HAL_SPI_Receive(&hspi3, &recv, 1, 1000);
if (rc == HAL_OK)
{
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_SET);
}
else
{
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_SET);
}
HAL_GPIO_TogglePin(GPIOE, GPIO_PIN_1);
HAL_Delay(1000);
}
/* USER CODE END 3 */
}The result I see is the yellow LED blinking, and the red one set, which means the slave reception didn't go well, I'm assuming because of a timeout. Also, I'm able to see the master SPI transactions in my logic analyzer:
What I'm expecting to happen is that the master sends the data to the slave, the slave receives it and puts it in its RxFIFO, and then (after the master finishes) I can read it.
What am I doing wrong?