Showing results for 
Search instead for 
Did you mean: 

STM32H7 SPI using common lines for two sensors and DMA

Associate III



I have been working on creating an SPI loop using the SPI callback function to alternate between two sensors that share a common SPI SDI/SDO line. However, I am encountering an issue where the SPI transfer complete callback is triggered, but the SPI transfer seems to not be fully completed because neither an error is called nor a data is transfered. As a result, the cycle stops after 2 or 3 iterations. I am unsure how to resolve this issue or understand why it is happening. Any insights or suggestions would be greatly appreciated.


My SPI callback function is this: 

void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi)

if (hspi->Instance == SPI2)
		/* De-select chip select */
		HAL_GPIO_WritePin(g_xImuHandle.hms1.csPort, g_xImuHandle.hms1.csPin, GPIO_PIN_SET);
		g_xGyroSamples.gyrox.value = HMS33_AngularRate(&DMA_RxBufferGyro1[3]);
		g_xGyroSamples.gyroxTemperature.value = HMS33_Temperature(&DMA_RxBufferGyro1[1]);

	if (hspi->Instance == SPI6)
			if (GyroSel == 2)
				HAL_GPIO_WritePin(g_xImuHandle.hms2.csPort, g_xImuHandle.hms2.csPin, GPIO_PIN_SET);
				g_xGyroSamples.gyroy.value = HMS33_AngularRate(&DMA_RxBufferGyro2[3]);
				g_xGyroSamples.gyroyTemperature.value = HMS33_Temperature(&DMA_RxBufferGyro2[1]);

				HAL_GPIO_WritePin(g_xImuHandle.hms3.csPort, g_xImuHandle.hms3.csPin, GPIO_PIN_RESET);
				HAL_SPI_TransmitReceive_DMA(g_xImuHandle.hms3.pxSpi, (uint8_t *)DMA_TxBuffer3, (uint8_t *)DMA_RxBufferGyro3, 6 );
				GyroSel = 3;

			if (GyroSel == 3)
				HAL_GPIO_WritePin(g_xImuHandle.hms3.csPort, g_xImuHandle.hms3.csPin, GPIO_PIN_SET);
				g_xGyroSamples.gyroz.value = HMS33_AngularRate(&DMA_RxBufferGyro3[3]);
				g_xGyroSamples.gyrozTemperature.value = HMS33_Temperature(&DMA_RxBufferGyro3[1]);

				HAL_GPIO_WritePin(g_xImuHandle.hms2.csPort, g_xImuHandle.hms2.csPin, GPIO_PIN_RESET);
				HAL_SPI_TransmitReceive_DMA(g_xImuHandle.hms2.pxSpi, (uint8_t *)DMA_TxBuffer2, (uint8_t *)DMA_RxBufferGyro2, 6 );
				GyroSel = 2;


  I start the cycle by calling HAL_SPI_TransmitRecieve_DMA()​ in the main function.