我正在尝试使用DMA在SPI中传输数据,因为我的Hal状态是HAL_SPI_STATUS_BUSY_TX。必需的状态为HAL_SPI_STATE_READY。我想通过SPI发送一些批量数据和命令(单字节)。是否可以分别在DMA和非DMA模式之间切换。如图所示,它在while中循环。
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中。
启用SPI后,NDTR = 0x00
发布于 2019-10-29 15:14:25
我把TX DMA流从DAM1_Stream7改成了DMA1_Stream2,问题就解决了。不知道为什么不在stream7工作的根本原因。
发布于 2019-10-04 20:01:14
可能导致这种问题的一个原因是,存储要发送的数据的变量被放在错误的RAM区域,请检查映射文件并修改链接器脚本
您可以在这里找到更多信息https://community.st.com/s/article/FAQ-DMA-is-not-working-on-STM32H7-devices
https://stackoverflow.com/questions/58185890
复制相似问题