打印

请求各位大佬给帮忙看看我这个dma串口收发数据

[复制链接]
444|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
jiaxxx|  楼主 | 2020-6-21 13:01 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
进不了串口中断,急求

#include "usart.h"
#include "dma.h"
#include "sys.h"         
#define UART_RX_LEN                128
u8 ccc=0;
u8 Res;
void uart_init(u32 bound){
  //GPIO¶Ë¿ÚÉèÖÃ
  GPIO_InitTypeDef GPIO_InitStructure;
        USART_InitTypeDef USART_InitStructure;
        NVIC_InitTypeDef NVIC_InitStructure;
         
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1|RCC_APB2Periph_GPIOA, ENABLE);        //ʹÄÜUSART1£¬GPIOAʱÖÓ

        //USART1_TX   GPIOA.9
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //PA.9
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;        //¸´ÓÃÍÆÍìÊä³ö
  GPIO_Init(GPIOA, &GPIO_InitStructure);//³õʼ»¯GPIOA.9

  //USART1_RX          GPIOA.10³õʼ»¯
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;//PA10
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//¸¡¿ÕÊäÈë
  GPIO_Init(GPIOA, &GPIO_InitStructure);//³õʼ»¯GPIOA.10  

  //Usart1 NVIC ÅäÖÃ
  NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=2;//ÇÀÕ¼ÓÅÏȼ¶3
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;                //×ÓÓÅÏȼ¶3
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;                        //IRQͨµÀʹÄÜ
        NVIC_Init(&NVIC_InitStructure);        //¸ù¾ÝÖ¸¶¨µÄ²ÎÊý³õʼ»¯VIC¼Ä´æÆ÷

   //USART ³õʼ»¯ÉèÖÃ

        USART_InitStructure.USART_BaudRate = bound;//´®¿Ú²¨ÌØÂÊ
        USART_InitStructure.USART_WordLength = USART_WordLength_8b;//×Ö³¤Îª8λÊý¾Ý¸ñʽ
        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(USART1, &USART_InitStructure); //³õʼ»¯´®¿Ú1
//  USART_ITConfig(USART1, USART_IT_RXNE, DISABLE);//¿ªÆô´®¿Ú½ÓÊÜÖжÏ
        USART_ITConfig(USART1, USART_IT_IDLE, ENABLE);
  USART_Cmd(USART1, ENABLE);   
//ʹÄÜ´®¿Ú1

}

void USART1_IRQHandler(void)                        //´®¿Ú1ÖжϷþÎñ³ÌÐò
{
                ccc=25;



          if (USART_GetFlagStatus(USART1, USART_FLAG_ORE) != RESET)//??!????if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)???
    {
        USART_ReceiveData(USART1);
    }
        if(USART_GetITStatus(USART1, USART_IT_IDLE) != RESET)  //½ÓÊÕÖжÏ(½ÓÊÕµ½µÄÊý¾Ý±ØÐëÊÇ0x0d 0x0a½áβ)
        {
         USART1->SR;  
   USART1->DR;
                ccc=2;
                Receive_DataPack();
                USART_ReceiveData(USART1);
        }
//        if(USART_GetITStatus(USART1,USART_IT_RXNE)!=RESET)
//        {               
//               
//       
//    Receive_DataPack();
//        }
}
void Receive_DataPack(void)
{

        uint32_t buff_length;
       
        DMA_Cmd(DMA1_Channel5, DISABLE);
       

        DMA_ClearFlag( DMA1_FLAG_TC5 );  

        buff_length = UART_RX_LEN         - DMA_GetCurrDataCounter(DMA1_Channel5);
   ccc=1;
        DMA_SetCurrDataCounter(DMA1_Channel5,UART_RX_LEN);   

        DMA_Cmd(DMA1_Channel5, ENABLE);      
       
}

使用特权

评论回复

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

2

主题

13

帖子

0

粉丝