STM32F4 SPI with DMA is not working, Transmit only used. stuck at HAL_SPI_STATE_BUSY_TX
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-11-15 4:35 AM
I have done the implementation of 3 wire SPI using DMA and when I do SPI transfer using
HAL_SPI_Transmit_DMA(&SPIx_handle, (uint8_t *)TxBuffer, 8u); the HAL_SPI_GetState(&SPIx_handle) is stuck at HAL_SPI_STATE_BUSY_TX.
Not changing the state.
My configuration of SPI and DMA is similar to this query : STM32F405 SPI Transmit using DMA not working
Thanks in advance
Edit: First time posting query here, if anything needed additionally please comment
Edit 2: Earlier mentioned HAL_SPI_STATE_BUSY, updated to HAL_SPI_STATE_BUSY_TX
Solved! Go to Solution.
- Labels:
-
DMA
-
SPI
-
STM32F4 Series
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-11-18 6:07 AM
> Issue is when the NSS is high, Clock also present.
The "NSS" signal on the STM32F4 is not a CS signal. It pulses at the end of each byte in TI mode, which is presumably what you have selected. You'll need to use a different method.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-11-15 4:43 AM
Ensure MX_DMA_Init is called before MX_SPI_Init.
If that's not it, show how you're using it or post the SPI and DMA register values.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-11-15 5:08 AM
Hi TDX,
Thanks for the response.
MX_DMA_Init is done before MX_SPI_Init
DMA2 Stream 4 and SPI5 is used.
please find the above images attached.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-11-15 5:26 AM
The DMA stream isn't enabled. Might be some flags set in DMA2_HISR.
Since NDTR=0, it could be that the transfer is complete, but you don't have the DMA transfer complete interrupt implemented or handled correctly, or interrupts are disabled.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-11-16 3:10 AM
Hi TDK,
Thanks for the response.
DMA stream is Enabled and TC and HF bits in HISR are getting set after Transfer.
NDTR is getting populated during transfer.
Still then
_inline_ static void spi5_dataTransfer(uint16_t *TxBuffer)
{
HAL_GPIO_WritePin(SPIx_NSS_Port, SPIx_NSS_Pin, GPIO_PIN_RESET);
HAL_SPI_Transmit_DMA(&SPIx_handle, (uint8_t *)TxBuffer, 8u);
HAL_GPIO_WritePin(SPIx_NSS_Port, SPIx_NSS_Pin, GPIO_PIN_SET);
while (HAL_SPI_GetState(&SPIx_handle) != HAL_SPI_STATE_READY);
}
the control is not stopping at while(mentioned above).
And SPI state remains in "HAL_SPI_STATE_BUSY_TX" state.
Please help me to understand, what made you think "but you don't have the DMA transfer complete interrupt implemented or handled correctly, or interrupts are disabled".
Kindly reply, its helping me to understand more.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-11-16 5:40 AM
You appear to try to use SPI with CRC, is it intentional?
Do you use C++?
JW
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-11-16 5:47 AM
Since TCIE is set and TCIF is set, and the cpu isn't jumping into the handler, the corresponding NVIC enable bit isn't set, interrupts are disabled, or a higher priority interrupt is being ran.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-11-16 6:01 AM
Hi JW,
Thanks for the response
I use C language.
My SPI is configured without CRC (SPI_CRCCALCULATION_DISABLE)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-11-16 6:04 AM
Hi TDK,
Thanks for the response
The NVIC is enabled, I will check by modifying interrupt priority.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-11-16 7:43 AM
Sorry I misread the bits in SPI_CR1, indeed, you don't have CRCEN set (rather, BIDIMODE and BIDIOE).
JW
