2021-11-15 04: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.
2021-11-18 06: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.
2021-11-15 04: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.
2021-11-15 05: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.
2021-11-15 05: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.
2021-11-16 03: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.
2021-11-16 05:40 AM
You appear to try to use SPI with CRC, is it intentional?
Do you use C++?
JW
2021-11-16 05: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.
2021-11-16 06:01 AM
Hi JW,
Thanks for the response
I use C language.
My SPI is configured without CRC (SPI_CRCCALCULATION_DISABLE)
2021-11-16 06:04 AM
Hi TDK,
Thanks for the response
The NVIC is enabled, I will check by modifying interrupt priority.
2021-11-16 07:43 AM
Sorry I misread the bits in SPI_CR1, indeed, you don't have CRCEN set (rather, BIDIMODE and BIDIOE).
JW