gpt4 book ai didi

c++ - STM32H7 SPI DMA传输,一直处于忙传输状态,HAL_SPI_STATE_BUSY_TX

转载 作者:太空宇宙 更新时间:2023-11-04 04:10:25 27 4
gpt4 key购买 nike

我正在尝试使用 DMA 在 SPI 中传输数据,因为我的 Hal 状态是 HAL_SPI_STATUS_BUSY_TX。所需状态为 HAL_SPI_STATE_READY。我想通过 SPI 发送一些批量数据和命令(单字节)。是否可以分别在 DMA 和非 DMA 模式之间切换。如图所示,它在 while 中循环。 enter image description here

hdma1_tx.Instance                 = DMA1_Stream7;
hdma1_tx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
hdma1_tx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
hdma1_tx.Init.MemBurst = DMA_MBURST_INC4;
hdma1_tx.Init.PeriphBurst = DMA_PBURST_INC4;
hdma1_tx.Init.Request = DMA_REQUEST_SPI1_TX;
hdma1_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
hdma1_tx.Init.PeriphInc = DMA_PINC_DISABLE;
hdma1_tx.Init.MemInc = DMA_MINC_ENABLE;
hdma1_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
hdma1_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
hdma1_tx.Init.Mode = DMA_NORMAL;
hdma1_tx.Init.Priority = DMA_PRIORITY_LOW;

if(HAL_DMA_Init(&hdma1_tx) != HAL_OK)
{
// Error
}

/* Associate the initialized DMA handle to the the SPI handle */
__HAL_LINKDMA(hspi, hdmatx, hdma1_tx);

/* Configure the DMA handler for Transmission process */
hdma_rx.Instance = DMA1_Stream1;
hdma_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
hdma_rx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
hdma_rx.Init.MemBurst = DMA_MBURST_INC4;
hdma_rx.Init.PeriphBurst = DMA_PBURST_INC4;
hdma_rx.Init.Request = DMA_REQUEST_SPI1_RX;
hdma_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
hdma_rx.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_rx.Init.MemInc = DMA_MINC_ENABLE;
hdma_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
hdma_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
hdma_rx.Init.Mode = DMA_NORMAL;
hdma_rx.Init.Priority = DMA_PRIORITY_HIGH;

HAL_DMA_Init(&hdma_rx);

/* Associate the initialized DMA handle to the the SPI handle */
__HAL_LINKDMA(hspi, hdmarx, hdma_rx);

/*##-4- Configure the NVIC for DMA #########################################*/
/* NVIC configuration for DMA transfer complete interrupt (SPI1_TX) */
HAL_NVIC_SetPriority(DMA1_Stream7_IRQn, 1, 1);
HAL_NVIC_EnableIRQ(DMA1_Stream7_IRQn);

HAL_NVIC_SetPriority(SPI1_IRQn, 1, 0);
HAL_NVIC_EnableIRQ(SPI1_IRQn);

HAL_STATUS 必须为 HAL_SPI_STATE_READY。

我的数据长度加载到 NDTR 中。 enter image description here

SPI使能后NDTR = 0x00

enter image description here

最佳答案

我将 TX DMA 流从 DAM1_Stream7 更改为 DMA1_Stream2,问题已解决。不知道为什么不在 stream7 工作的根本原因。

关于c++ - STM32H7 SPI DMA传输,一直处于忙传输状态,HAL_SPI_STATE_BUSY_TX,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58185890/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com