STM32F10x 学习笔记8(USART实现串口通讯 DMA 方式)
时间:11-20
来源:互联网
点击:
- T2,ENABLE);
- USART_InitStructure.USART_BaudRate=9600;
- 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(USART2,&USART_InitStructure);
- USART_Cmd(USART2,ENABLE);
- NVIC_InitStructure.NVIC_IRQChannel=USART2_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority=1;
- NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
- NVIC_Init(&NVIC_InitStructure);
- }
- voidUART2_TX_DMA_Init(uint8_t*p_str,uint16_tcnt)
- {
- //DMA_InitTypeDefDMA_InitStructure;
- //DMA_InitStructure.DMA_PeripheralBaseAddr=(uint32_t)&(USART2->DR);
- //DMA_InitStructure.DMA_MemoryBaseAddr=(uint32_t)str;
- //DMA_InitStructure.DMA_DIR=DMA_DIR_PeripheralDST;
- //DMA_InitStructure.DMA_BufferSize=14;
- //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_Low;
- //DMA_InitStructure.DMA_M2M=DMA_M2M_Disable;
- RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1,ENABLE);
- //DMA_Init(DMA1_Channel7,&DMA_InitStructure);
- DMA1_Channel7->CPAR=(uint32_t)&(USART2->DR);
- DMA1_Channel7->CMAR=(uint32_t)p_str;
- DMA1_Channel7->CNDTR=cnt;
- DMA1_Channel7->CCR=DMA_DIR_PeripheralDST|DMA_Priority_Low|
- DMA_Mode_Normal|DMA_PeripheralInc_Disable|
- DMA_MemoryInc_Enable|DMA_PeripheralDataSize_Byte|
- DMA_MemoryDataSize_Byte|DMA_M2M_Disable;
- }
- OS_EVENT*UART2_DMA_TX_Sem;
- uint8_tstr[]="HelloWorld!!!";
- voidTaskStart(void*pdata)
- {
- unsignedcharerr;
- SysTick_Config(SystemCoreClock/10);
- USART2_Init();
- USART_DMACmd(USART2,USART_DMAReq_Tx,ENABLE);
- UART2_TX_DMA_Init(str);
- UART2_DMA_TX_Sem=OSSemCreate(1);
- for(;;)
- {
- LED_Spark();
- OSSemPend(UART2_DMA_TX_Sem,0,&err);
- //DMA_Cmd(DMA1_Channel7,DISABLE);
- DMA1_Channel7->CCR&=(uint16_t)(~DMA_CCR1_EN);
- //DMA_Init(DMA1_Channel7,&DMA_InitStructure);
- DMA1_Channel7->CNDTR=14;
- //DMA_Cmd(DMA1_Channel7,ENABLE);
- DMA1_Channel7->CCR|=DMA_CCR1_EN;
- //USART_DMACmd(USART2,USART_DMAReq_Tx,ENABLE);
- OSTimeDly(10);
- }
- }
- intmain(void)
- {
- SystemInit();
- LED_Init();
- OSInit();
- OSTaskCreate(TaskStart,(void*)0,&(TaskStartStk[TASK_STK_SIZE-1]),1);
- OSStart();
- for(;;)
- {
- }
- }
- voidDMA1_Channel7_IRQHandler(void)
- {
- OS_CPU_SRcpu_sr;
- OS_ENTER_CRITICAL();/*TelluC/OS-IIthatwearestartinganISR*/
- OSIntNesting++;
- OS_EXIT_CRITICAL();
- OSSemPost(UART2_DMA_TX_Sem);
- //UART_PutChar(USART2,+);
- DMA1->IFCR=DMA1_FLAG_TC7;
- OSIntExit();
- }
STM32F10xUSART串口通讯DMA方 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)