cancel
Showing results for 
Search instead for 
Did you mean: 

SPI LOOP BACK TEST on STM32H563ZIT6

Berlin-raj123
Associate III

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.

1 ACCEPTED SOLUTION

Accepted Solutions
SMarie
Senior

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.

View solution in original post

9 REPLIES 9
TDK
Guru

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.

 

If you feel a post has answered your question, please click "Accept as Solution".

can i connect both cs pins?

can you please tell me the hardware connection?

SMarie
Senior

Both CS? Are you using two or one SPI?

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

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

 

 

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.

If you feel a post has answered your question, please click "Accept as Solution".

can you check my code above?

SMarie
Senior

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.