2020-05-13 12:37 AM
Hello everybody!
I was wondering if the time of the HAL_SPI_Transmit function can be shorter. (see the picture for more info) ,
I use the STM32L031K6 dev. board which runs at 32 MHz with a ARM Cortex -M0+. I set de the baudrate to (/2), which is max, for shorten the SPI_message time. Sadly, nothing changed to the time duration before and after the message. I use __HAL_SPI_ENABLE and __HAL_SPI_DISABLE to control the SSEL (slave select) by hardware control for further speed optimalisation.
I understand it could be possible that it is on the limit now but I think the time it takes to send the message out takes too long. (see picture)
Red is the SEL line and blue is the SDA line.
As you can see the time of the SPI message takes approx. 2 µs to transmit. The time before and after the message takes around 9 µs. It is already quite fast but my goal is to put everything withing 15 µs.
Code of what it is doing here:
__HAL_SPI_ENABLE(&hspi1); //SSEL low
HAL_SPI_Transmit(&hspi1, spiData, 1, 1); //Transmit data
__HAL_SPI_DISABLE(&hspi1); //SSEL high
I know it is quite in depth but hopefully somebody can help me with this optimalisation.
Cheers!
Jasper
Solved! Go to Solution.
2020-05-13 01:08 AM
Yes. Don't use HAL, it is slow. Use the faster and better documented register interface instead.
Follow the step-by-step procedures in the SPI chapter of the reference manual.
Untested code, I don't have any STM32L0.
SPI1->CR1 |= SPI_CR1_SPE;
while((SPI1->SR & SPI_SR_TXE) == 0)
;
SPI1->DR = *spidata;
while((SPI1->SR & SPI_SR_TXE) == 0)
;
while(SPI1->SR & SPI_SR_BSY)
;
SPI1->CR1 &= ~SPI_CR1_SPE;
2020-05-13 01:08 AM
Yes. Don't use HAL, it is slow. Use the faster and better documented register interface instead.
Follow the step-by-step procedures in the SPI chapter of the reference manual.
Untested code, I don't have any STM32L0.
SPI1->CR1 |= SPI_CR1_SPE;
while((SPI1->SR & SPI_SR_TXE) == 0)
;
SPI1->DR = *spidata;
while((SPI1->SR & SPI_SR_TXE) == 0)
;
while(SPI1->SR & SPI_SR_BSY)
;
SPI1->CR1 &= ~SPI_CR1_SPE;
2020-05-13 02:17 AM
It works! much faster now! thanks a lot!
2022-08-01 01:57 AM
Hello,
Do you have 16 bits version of code?
BR,
Terry