我想实现串口dma发送数据,目前串口是通的,不用dma串口可以正常发送数据,我不确定dma哪里写的有问题,用dma发送数据无法发送,也不会进入dma数据发送完成的中断函数,有了解STM32F072C8T6 串口dma的吗?请指导下,谢谢!
以下是DMA的初始化和中断处理函数
void initUartDMA(void)
{
config_dma(DMA1_Channel2,DMA_DIR_PeripheralDST, (uint32_t)&USART1->TDR,(uint32_t)uart1_dma_tx_buf,UART1_SENDBUF_SIZE);
dma_tcirq_enable();
}
void config_dma(DMA_Channel_TypeDef *DMA_Channelx,uint32_t w2w, uint32_t par,uint32_t mar,uint16_t ndtr)
{
DMA_InitTypeDef DMA_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1,ENABLE);
DMA_DeInit(DMA_Channelx); //初始化相关的寄存器
DMA_InitStructure.DMA_PeripheralBaseAddr = par;//DMA外设地址
DMA_InitStructure.DMA_MemoryBaseAddr = mar;//DMA 存储器0地址
DMA_InitStructure.DMA_DIR = w2w;//存储器到外设模式
DMA_InitStructure.DMA_BufferSize = ndtr;//数据传输量
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;//外设非增量模式
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;//存储器增量模式
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;//外设数据长度:8位
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;//存储器数据长度:8位
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;// 使用普通模式
DMA_InitStructure.DMA_Priority = DMA_Priority_Medium;//中等优先级
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA_Channelx, &DMA_InitStructure);//初始化DMA Stream
}
void dma_tcirq_enable(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
//开启传输完成中断.
DMA_ITConfig(DMA1_Channel2, DMA_IT_TC, ENABLE);
//dma NVIC 配置
NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel2_3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
NVIC_Init(&NVIC_InitStructure); //根据指定的参数初始化VIC寄存器、
}
void DMA1_Channel2_3_IRQHandler(void)
{
dma1_ch2_irq = 1;
//DMA2_Stream7传输完成之后便会触发并进入该中断.
if(DMA_GetITStatus(DMA1_IT_TC2) != RESET) //
{
DMA_ClearITPendingBit(DMA1_IT_TC2);
//代表发送完成.可以使用DMA进行下一次的数据发送.
dma1_is_idle = 1;
}
}
串口数据发送
int8_t usingdma_send_frame(DMA_Channel_TypeDef *DMA_Channelx,uint16_t ndtr)
{
static uint8_t retry;
retry = 0;
if (dma1_is_idle) {
dma1_is_idle = 0;
DMA_SetCurrDataCounter(DMA_Channelx,ndtr); //数据传输量
DMA_Cmd(DMA_Channelx, ENABLE); //开启DMA传输
return 0;
} else {
printf("dma1_is_idle == 0");
return -1; //DMA2stream7 is busy
}
}
|