cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H7 HAL SPI too slow for my application

Brother Theo
Associate II

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 

2 REPLIES 2
STTwo-32
ST Employee

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 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

TDK
Guru

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.

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