串口使用DMA發(fā)送,使用DMA_Mode_Normal模式,怎么來手動觸發(fā)發(fā)送?
DMA設(shè)置如下:
void bsp_InitHardUart(void)
{
? ? GPIO_InitTypeDef GPIO_InitStructure = {0};
? ? USART_InitTypeDef USART_InitStructure = {0};
? ? DMA_InitTypeDef DMA_InitStructure = {0};
? ? NVIC_InitTypeDef NVIC_InitStructure = {0};
? ? RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOB | RCC_APB2Periph_USART1, ENABLE);
? ? RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
? ? // USART1 TX->B.6 ? RX->B.7
? ? GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
? ? GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
? ? GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
? ? GPIO_Init(GPIOB, &GPIO_InitStructure);
? ? GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
? ? GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;
? ? GPIO_Init(GPIOB, &GPIO_InitStructure);
? ? // USART1重映射至PB6、PB7
? ? GPIO_PinRemapConfig(GPIO_Remap_USART1, ENABLE);
? ? // 配置串口1
? ? USART_DeInit(USART1);
? ? 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_Tx | USART_Mode_Rx;
? ? USART_Init(USART1, &USART_InitStructure);
? ? // 配置DMA
? ? DMA_DeInit(DMA1_Channel4);
? ? DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&USART1->DATAR;
? ? DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&ucaTxBuffer;
? ? DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
? ? DMA_InitStructure.DMA_BufferSize = FRAME_SIZE;
? ? DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
? ? DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
? ? DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
? ? DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
? ? DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
? ? DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
? ? DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
? ? DMA_Init(DMA1_Channel4, &DMA_InitStructure);
? ? DMA_DeInit(DMA1_Channel5);
? ? DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&USART1->DATAR;
? ? DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&ucaRxBuffer;
? ? DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
? ? DMA_InitStructure.DMA_BufferSize = FRAME_SIZE;
? ? DMA_Init(DMA1_Channel5, &DMA_InitStructure);
? ? // 啟用 USART DMA 接口
? ? USART_DMACmd(USART1, USART_DMAReq_Tx, ENABLE);
? ? // 使能 DMA 通道傳輸
? ? DMA_Cmd(DMA1_Channel4, ENABLE); // USART1_TX
? ? DMA_Cmd(DMA1_Channel5, ENABLE); // USART1_RX
? ? // 設(shè)置中斷優(yōu)先級
? ? NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn; ? ? ? ? // IRQ通道
? ? NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; // 搶占優(yōu)先級別
? ? NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; ? ? ? ?// 從優(yōu)先級別
? ? NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; ? ? ? ? ? // 使能
? ? NVIC_Init(&NVIC_InitStructure);
? ? // 使能串口接收中斷
? ? USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
? ? // 使能串口
? ? USART_Cmd(USART1, ENABLE);
}