Skip to main content
Visitor II
July 15, 2024
Solved

SPI LOOP BACK TEST on STM32H563ZIT6

  • July 15, 2024
  • 3 replies
  • 3447 views

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.

    This topic has been closed for replies.
    Best answer by SMarie

    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.

    3 replies

    Super User
    July 15, 2024

    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.

     

    Visitor II
    July 15, 2024

    can i connect both cs pins?

    Visitor II
    July 15, 2024

    can you please tell me the hardware connection?

    Graduate II
    July 15, 2024

    Both CS? Are you using two or one SPI?

    Visitor II
    July 15, 2024

    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

    Visitor II
    July 15, 2024

    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 */
    }

     

     

    SMarieAnswer
    Graduate II
    July 16, 2024

    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.