标签:
1
2
3
//DMAxµÄ¸÷ͨµÀÅäÖà //ÕâÀïµÄ´«ÊäÐÎʽÊǹ̶¨µÄ,ÕâµãÒª¸ù¾Ý²»Í¬µÄÇé¿öÀ´ÐÞ¸Ä //´Ó´æ´¢Æ÷->ÍâÉèģʽ/8λÊý¾Ý¿í¶È/´æ´¢Æ÷ÔöÁ¿Ä£Ê½ //DMA_Streamx:DMAÊý¾ÝÁ÷,DMA1_Stream0~7/DMA2_Stream0~7 //chx:DMAͨµÀÑ¡Ôñ,@ref DMA_channel DMA_Channel_0~DMA_Channel_7 //par:ÍâÉèµØÖ· //mar:´æ´¢Æ÷µØÖ· //ndtr:Êý¾Ý´«ÊäÁ¿ void MYDMA_Config(DMA_Stream_TypeDef *DMA_Streamx,u32 chx,u32 par,u32 mar,u16 ndtr) { DMA_InitTypeDef myDMA; //ʹÄÜDMAµÄʱÖÓ if((u32)DMA_Streamx>(u32)DMA2) RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2,ENABLE); else RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1,ENABLE); // myDMA.DMA_BufferSize=ndtr; //DMA_SxNDTR[15:0] Êý¾Ý´«ÊäÁ¿£¬Ö»ÓнûÖ¹´«ÊäµÄʱºò£¬²ÅÄÜдÈë¡£Æô¶¯´«Êäºó£¬±íʾʣÓàÊý¾ÝÁ¿ myDMA.DMA_Channel= DMA_Channel_4; //DMA_SxCR[27:25] ͨµÀÑ¡Ôñ myDMA.DMA_DIR=DMA_DIR_MemoryToPeripheral; //DMA_SxCR[7:6] ´«Êä·½Ïò ´æ´¢Æ÷µ½ÍâÉè myDMA.DMA_FIFOMode=DMA_FIFOMode_Disable; //DMA_SxFCR[2] ʹÄÜÖ±½Óģʽ myDMA.DMA_FIFOThreshold=DMA_FIFOThreshold_Full;//DMA_SxFCR[1:0] ʹÓÃÖ±½Óģʽ£¬Õâ¸öÅä²»Å䶼¿ÉÒÔ myDMA.DMA_Memory0BaseAddr=mar; // DMA_SxM0AR[] ´æ´¢Æ÷µØÖ· myDMA.DMA_MemoryBurst=DMA_MemoryBurst_Single; // DMA_SxCR[24:23]Í»·¢´«ÊäÅäÖà myDMA.DMA_MemoryDataSize=DMA_MemoryDataSize_Byte;//DMA_SxCR[14:13] ´æ´¢Æ÷Êý¾Ý´óС myDMA.DMA_MemoryInc=DMA_MemoryInc_Enable; //DMA_SxCR[10] ´æ´¢Æ÷µØÖ·µÝÔö myDMA.DMA_Mode= DMA_Mode_Normal ; //DMA_SxCR[8] ½ûֹѻ·Ä£Ê½ myDMA.DMA_PeripheralBaseAddr=par; //ÍâÉèµØÖ· DMA_SxPAR myDMA.DMA_PeripheralBurst= DMA_PeripheralBurst_Single; ////DMA_SxCR[22:21] ÍâÉèÍ»·¢ÅäÖà myDMA.DMA_PeripheralDataSize=DMA_PeripheralDataSize_Byte; //DMA_SxCR[12:11] ÍâÉèÊý¾Ý´óС myDMA.DMA_PeripheralInc= DMA_PeripheralInc_Disable; //DMA_SxCR[9] ÍâÉèµØÖ·¹Ì¶¨ myDMA.DMA_Priority= DMA_Priority_Medium;//ÖеÈÓÅÏȼ¶ DMA_SxCR[17:16] DMA_Init(DMA_Streamx, &myDMA); //³õʼ»¯ } // Íê³ÉÒ»´Î´«Êä void MYDMA_Enable(DMA_Stream_TypeDef *DMA_Streamx,u16 ndtr) { DMA_Cmd(DMA_Streamx,DISABLE); //¹Ø±ÕDMA´«Êä DMA_SxCR[0] ENλ while (DMA_GetCmdStatus(DMA_Streamx) != DISABLE){} //ÔٴζÁENλ£¬È·±£ÊDz»¿É¶ÁµÄ DMA_SetCurrDataCounter(DMA_Streamx,ndtr); //DMA_SxNDTR[15:0]´«ÊäµÄÊý¾ÝÁ¿£¬ÔÙ´Îд DMA_Cmd(DMA_Streamx,ENABLE); //ʹÄÜ }
1
2
3
#define SEND_BUF_SIZE 8200 //·¢ËÍÊý¾Ý³¤¶È,×îºÃµÈÓÚsizeof(TEXT_TO_SEND)+2µÄÕûÊý±¶. u8 SendBuff[SEND_BUF_SIZE]; //·¢ËÍÊý¾Ý»º³åÇø const u8 TEXT_TO_SEND[]={"123456789abcde"}; int main(void) { u8 b; u16 i; u8 t=0; u8 j,mask=0; float pro=0;//½ø¶È NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//ÉèÖÃϵͳÖжÏÓÅÏȼ¶·Ö×é2 delay_init(168); //³õʼ»¯ÑÓʱº¯Êý uart_init(115200); //³õʼ»¯´®¿Ú²¨ÌØÂÊΪ115200 LED_Init(); //³õʼ»¯LED LCD_Init(); //LCD³õʼ»¯ KEY_Init(); //°´¼ü³õʼ»¯ MYDMA_Config(DMA2_Stream7,DMA_Channel_4,(u32)&USART1->DR,(u32)SendBuff,SEND_BUF_SIZE);//DMA2,STEAM7,CH4,ÍâÉèΪ´®¿Ú1,´æ´¢Æ÷ΪSendBuff,³¤¶ÈΪ:SEND_BUF_SIZE. POINT_COLOR=RED; LCD_ShowString(30,50,200,16,16,"Explorer STM32F4"); LCD_ShowString(30,70,200,16,16,"DMA TEST"); LCD_ShowString(30,90,200,16,16,"ATOM@ALIENTEK"); LCD_ShowString(30,110,200,16,16,"2014/5/6"); LCD_ShowString(30,130,200,16,16,"KEY0:Start"); POINT_COLOR=BLUE;//ÉèÖÃ×ÖÌåΪÀ¶É« // //Ìî³äram // j=sizeof(TEXT_TO_SEND); // for(i=0;i<SEND_BUF_SIZE;i++)//Ìî³äASCII×Ö·û¼¯Êý¾Ý // { // if(t>=j)//¼ÓÈë»»Ðзû // { // if(mask) // { // SendBuff[i]=0x0a; // t=0; // }else // { // SendBuff[i]=0x0d; // mask++; // } // }else//¸´ÖÆTEXT_TO_SENDÓï¾ä // { // mask=0; // SendBuff[i]=TEXT_TO_SEND[t]; // t++; // } // } j=sizeof(TEXT_TO_SEND)+1; for(i=0;i<SEND_BUF_SIZE;i++) { b= i% j; if(b==j-2) SendBuff[i]=0x0d; if(b==j-1) SendBuff[i]=0x0a; if(b<j-2) SendBuff[i]=TEXT_TO_SEND[b]; } POINT_COLOR=BLUE;//ÉèÖÃ×ÖÌåΪÀ¶É« i=0; while(1) { t=KEY_Scan(0); if(t==KEY0_PRES) { printf("start to transfer date from ram to uart by DMA\r\n"); USART_DMACmd(USART1,USART_DMAReq_Tx,ENABLE); MYDMA_Enable(DMA2_Stream7,SEND_BUF_SIZE); while(1) { if(DMA_GetFlagStatus(DMA2_Stream7,DMA_FLAG_TCIF7)!=RESET) { DMA_ClearFlag(DMA2_Stream7,DMA_FLAG_TCIF7); break; } pro=DMA_GetCurrDataCounter(DMA2_Stream7); pro=1-pro/SEND_BUF_SIZE; pro=pro*100; //delay_ms(20); //printf("have already transfer %f percent data",pro); } printf("\r\n transfer finish"); } }
标签:
原文地址:http://www.cnblogs.com/nasduc/p/5049788.html