2017-10-09 02:04 AM
Hi,
I am using SPI1 peripheral as master at 16 MHz on STM32L443, I can send and receive data correctly using DMA.
My application requires to speed down SPI to 1MHz during a moment so I changed SPI baud rate on the fly (by writing SPI_CR1 register). Using SPI polling API this is working fine but using DMA I noticed that SPI speed is still 16MHz.
I tried to:
- DeInit()/Init() DMA configuration
- Relink DMA to SPI
- DeInit()/Init() SPI with new baud rate
but result is the same.
For some reason it looks like first SPI configuration is permanent for DMA.
Did I miss something to reconfigure?
Thanks,
#dma #spi #baud-rate2017-10-09 02:16 AM
Read out the SPI registers before and after the change and compare (or post them).
JW
2017-10-09 04:36 AM
Only BR field from CR1 has changed, the register value changed from 0x0000034C to 0x0000036C. It looks consistent to change from prescaler 4 to 64.
2017-10-09 04:47 AM
And after this change, you see increase on the SPI clock from 16MHz to 20MHz?
How exactly do you observe the respective SPIx_SCK pin? Which pin is it?
JW
2017-10-09 04:57 AM
Don't you have I2S enabled by any chance?
JW
2017-10-09 05:02 AM
After this change I see SPI clock updated correctly to 1MHz using HAL_SPI_Receive(), but is still 16MHz using HAL_SPI_Receive_DMA().
I probe SPI communication using logic analyzer.
Pin configuration is:
PA8 ------> SPI1_NSS as GPIO
PA5 ------> SPI1_SCK PA6 ------> SPI1_MISO PA7 ------> SPI1_MOSI2017-10-09 05:03 AM
No
2017-10-09 05:22 AM
but is still 16MHz using HAL_SPI_Receive_DMA()
And *after* using HAL_SPI_Receive_DMA(), what's the content of SPI control registers?
JW
2017-10-09 07:04 AM
OK I found my mistake: SPI was configured to 1MHz then back to 16MHz after SPI Transmit function return. In DMA mode the function will return while transmission is on going. Waiting TX complete callback to reconfigure SPI back to 16MHz solve the issue.
Thanks,