Skip to main content
Visitor II
December 19, 2023
Question

STM32H7 HAL SPI too slow for my application

  • December 19, 2023
  • 2 replies
  • 1716 views

I'm using HAL SPI drivers to read some MCP23S17 expander chips. I am sending a 2 byte command and receiving a 6 byte response. The trouble is there is 6 mS of delay between the write and read. Code:

 

	// read encoder expander chips for encoder button data
	HAL_GPIO_WritePin(GPIOG, ENC_CS1_Pin, GPIO_PIN_RESET);	// enable selector output
	// do the transaction
	HAL_SPI_Transmit(&hspi1, tx_data, 2, HAL_MAX_DELAY);
	HAL_SPI_Receive(&hspi1, RawEncData1, 6, HAL_MAX_DELAY);
	// disable selector output
	HAL_GPIO_WritePin(GPIOG, ENC_CS1_Pin, GPIO_PIN_SET);	// enable selector output

 

I am using software NSS lines. Are there tricks to make the receive command happen faster? Or is there another driver besides HAL that runs faster?

-- Tim Ressel 

    This topic has been closed for replies.

    2 replies

    Technical Moderator
    December 19, 2023

    Hello @Brother Theo 

    You may think about using the SPI LL module driver that may help you. Also, you can even use the direct register programming. Finally, you may think about using DMA for the data transfer operation. 

    Best Regards.

    STTwo-32 

    Super User
    December 19, 2023

    You can use high optimization settings. Set the configuration to Release instead of Debug and that will speed things up quite a bit. Project -> Build Configurations -> Set Active -> Release.

    Using register access for SPI instead of HAL is fairly straightforward especially on the STM32H7 and will be the fastest way to use SPI.