我用DMA发送串口数据,如何启动传输呢,是要专门设置定时器启动吗?
软件启动DMA,然后每当发送寄存器空时,DMA传送一次数据
详见STM32参考手册的24.3.12节。
看你想怎么启动了
DMA的启动方式有很多中种的
如果你需要定时来启动就用定时器来启动
但是从你说的来看是想通过串口的收发来启动传输
可以看一下USART里面的DMA模式
还是不启动
按照参考手册和例程程序的顺序都试了,还是不能启动传输。
初始化程序:
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
/* Configure USARTx_Tx as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIOA_Tx1Pin;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure USARTx_Rx as input floating */
GPIO_InitStructure.GPIO_Pin = GPIOA_Rx1Pin;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
DMA_UART1Tx_StructInit();
DMA_Init(DMA1_Channel4, &DMA_UART1TxStructure);
BSP_IntVectSet(BSP_INT_ID_DMA1_CH4, DMA1_CH4_Uart1TxFinish);
BSP_IntPrioSet(BSP_INT_ID_DMA1_CH4, DMA1_CH4_UART1Tx_UIP);
BSP_IntEn(BSP_INT_ID_DMA1_CH4);
/* USARTx configuration ------------------------------------------------------*/
/* USARTx configured as follow:
- BaudRate = 115200 baud
- Word Length = 8 Bits
- One Stop Bit
- No parity
- Hardware flow control disabled (RTS and CTS signals)
- Receive and transmit enabled
*/
USART_InitStructure.USART_BaudRate = 115200;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No ;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART1, &USART_InitStructure);
USART_DMACmd(USART1, USART_DMAReq_Tx, ENABLE);
发送子程序:
DMA_Cmd(DMA1_Channel4, DISABLE);
DMA_UART1TxStructure.DMA_MemoryBaseAddr = (u32)TxBuf;
DMA_UART1TxStructure.DMA_BufferSize = temp;
DMA_Init(DMA1_Channel4, &DMA_UART1TxStructure);
DMA_Cmd(DMA1_Channel4, ENABLE);
USART_Cmd(USART1, ENABLE);
这样还是不行,运行后没有数据从串口发出去。
找到了问题的原因
问题出在了 DMA_UART1TxStructure.DMA_PeripheralBaseAddr 这个地址变量的赋值上,我是这样操作的:
DMA_UART1TxStructure.DMA_PeripheralBaseAddr = (u32)USART1->DR;
这样也试过:
DMA_UART1TxStructure.DMA_PeripheralBaseAddr = USART1->DR;
两种方式的结果 DMA_PeripheralBaseAddr 都是 0。
后来我直接地址赋值问题就解决了:
DMA_UART1TxStructure.DMA_PeripheralBaseAddr = 0x40013804;
USART1->DR 是接收数据寄存器地址,为什么它的地址值是 0 呢?
请问香主你的STM32 手册能不能给个下载链接 啊
我想看看
谢谢