2024-07-15 06:34 AM
Hi,
I would like to check whether it is possible to perform internal SPI full duplex loop back tests on the STM32H563ZIT6 board, but I don't know how to do it.any one please help me.
Solved! Go to Solution.
2024-07-16 12:31 AM
First, if your SPIs are correctly configured in SPI2 -> master and SPI3 -> slave, your connection should be:
SPI2 CLK <--> SPI3 CLK
SPI2 MOSI <--> SPI3 MOSI
SPI2 MISO <--> SPI3 MISO
SPI2 CS <--> SPI3 CS
Then, as @TDK said above, you should start with a non blocking function for the slave to receive before sending anything with the master. Like HAL_SPI_Receive_IT. But you'll probably need a few more configurations in your project to enable SPI IT if not already done.
2024-07-15 06:52 AM
If you physically connect the MOSI and MISO pins and treat it as an SPI master, it will receive the same data that it sends out. This is the closest you can get to a loopback in SPI.
2024-07-15 07:42 AM
can i connect both cs pins?
2024-07-15 07:58 AM
can you please tell me the hardware connection?
2024-07-15 08:12 AM
Both CS? Are you using two or one SPI?
2024-07-15 08:39 AM
For SPI checking purposes only, whether to transmit data from SPI1 to SPI2 on the STM32H563ZIT6 microcontroller or to perform a single SPI transmit and receive operation
tell me single spi transmit and receive hardware setup
2024-07-15 08:51 AM
now i am connecting that to transmit data from SPI1 to SPI2 on the STM32H563ZIT6
spi2--->full duplex master
spi3---->full duplex slave
spi2_clk to spi3_clk
spi2_mosi to spi3_miso
spi2_miso to spi3_mosi
uint8_t txData = 0x55; // Example data to transmit
uint8_t rxData = 0;
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_SPI2_Init();
MX_SPI3_Init();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/* Infinite loop */
// Transmit data from SPI1 to SPI2
HAL_SPI_Transmit(&hspi2, &txData, 1, HAL_MAX_DELAY);
HAL_SPI_Receive(&hspi3, &rxData, 1, HAL_MAX_DELAY);
// Check if the received data is correct
if (rxData == txData)
{
HAL_GPIO_WritePin(GPIOG,GPIO_PIN_13,SET);
}
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
2024-07-15 04:31 PM - edited 2024-07-15 04:32 PM
Yes, you would connect the CS pins. Not sure I'd call it a loop-back, it's just a normal SPI connection on both sides.
SPI slave needs to call and be waiting within HAL_SPI_Receive before master calls HAL_SPI_Transmit. You'll need to use asynchronous functions on one side or the other, or both.
2024-07-15 09:39 PM
can you check my code above?
2024-07-16 12:31 AM
First, if your SPIs are correctly configured in SPI2 -> master and SPI3 -> slave, your connection should be:
SPI2 CLK <--> SPI3 CLK
SPI2 MOSI <--> SPI3 MOSI
SPI2 MISO <--> SPI3 MISO
SPI2 CS <--> SPI3 CS
Then, as @TDK said above, you should start with a non blocking function for the slave to receive before sending anything with the master. Like HAL_SPI_Receive_IT. But you'll probably need a few more configurations in your project to enable SPI IT if not already done.