usart用DMA方式接收不,也保存不了,谁有从串口发送数据到LCD上显示的,也可以发给我参考一下,程序如下:

2019-10-12 13:28发布

//DMA#define USART_LENTH_BUF  64
u8 USART_RX_BUF[USART_LENTH_BUF];  //½óêÕ»o′棬×î′ó64
u8 USART_TX_BUF[USART_LENTH_BUF];  //·¢Ëí»o′棬×î′ó64
u32 USART_Rx=0; //½óêÕμ½μÄêy¾Y
u8 LENTH_USART = 0; //½óêÕμ½μÄêy¾YμÄ3¤¶è



DMA_InitTypeDef DMA_InitStructure;

        DMA_DeInit(DMA1_Channel5);
        DMA_InitStructure.DMA_PeripheralBaseAddr=(u32)&USART1->DR;   //íaéèμØÖ·
        DMA_InitStructure.DMA_MemoryBaseAddr=(u32)USART_RX_BUF;
        DMA_InitStructure.DMA_DIR=DMA_DIR_PeripheralSRC;  //íaé裬×÷ÎaÄ¿μÄμØÖ·
        DMA_InitStructure.DMA_BufferSize=64;
        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_High;
        DMA_InitStructure.DMA_M2M=DMA_M2M_Disable;
        DMA_Init(DMA1_Channel5,&DMA_InitStructure);
        DMA_Cmd(DMA1_Channel5, ENABLE);
        /* Enable USART1 DMA RX request */
  USART_DMACmd(USART1, USART_DMAReq_Rx, ENABLE);



//usart配置
USART_InitTypeDef  USART_InitStructure;

        USART_InitStructure.USART_BaudRate=9600;   //éèÖÃ′®¿úí¨DÅê±μÄ2¨ìØÂêÎa921600
        USART_InitStructure.USART_WordLength=USART_WordLength_8b;  //éèÖÃêy¾Yλ3¤¶è8¸öλ
        USART_InitStructure.USART_StopBits=USART_StopBits_1;      //ÔúÖ¡½áÎ2′«êä1¸öí£Ö1λ
        USART_InitStructure.USART_Parity=USART_Parity_No;           //éèÖÃD£Ñéλ¡°ÎT¡±
        USART_InitStructure.USART_HardwareFlowControl=USART_HardwareFlowControl_None;   //éèÖÃó2¼t¿ØÖÆá÷ê§Äü
        USART_InitStructure.USART_Mode=USART_Mode_Rx|USART_Mode_Tx;   //éèÖ÷¢Ëíoí½óêÕê1Äü

        USART_Init(USART1,&USART_InitStructure);
       
        USART_ITConfig(USART1, USART_IT_IDLE, ENABLE);  //èô×üÏß¿ÕÏD£¬2úéúÖD¶Ï
        //USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);   //½óêÕÖD¶ÏÔêDí
        USART_Cmd(USART1,ENABLE);          //¿aÆôUSART1
        USART_ClearFlag(USART1,USART_FLAG_TC);




//usart1中断处理


extern u8 LENTH_USART;
u8 FLAG_USART_RX=0;

void USART1_IRQHandler(void)
{
        u8  i=0;

        if(USART_GetITStatus(USART1, USART_IT_IDLE) != RESET)//ÅD¶ÏêÇ2»êǽóêÕÖD¶Ï
        {
                 i = USART1->SR;
                 i = USART1->DR;
                 DMA_Cmd(DMA1_Channel5, DISABLE); //1رÕDMA
                 USART_ClearITPendingBit(USART1, USART_IT_IDLE);//Çå3yÖD¶Ï±êÖ¾
                 USART_ITConfig(USART1, USART_IT_IDLE, DISABLE); //½ûÖ1ÖD¶Ï£¬·àÖ1¸2¸Ç
                 LENTH_USART = 64 -  DMA_GetCurrDataCounter(DMA1_Channel5);  //μÃμ½ÕæÕyμĽóêÕ¸öêy
                 DMA1_Channel5->CNDTR = 64; //ÖØDÂéèÖýóêÕ¸öêy
                 DMA_Cmd(DMA1_Channel5, ENABLE);  //¿aÆôDMA
                 FLAG_USART_RX = 1; //½óêÕ±ê־λÖÃò»
                 USART_ITConfig(USART1, USART_IT_IDLE, ENABLE);  //Ôù′οaÆôÖD¶Ï
                 printf("LENTH_USART=%d ",LENTH_USART);
                 
        }


}





友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。