<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > stm32的DMA空閑中斷數(shù)據(jù)配置

          stm32的DMA空閑中斷數(shù)據(jù)配置

          作者: 時間:2016-12-03 來源:網(wǎng)絡(luò) 收藏
          對于串口2的示例:

          void USART2_Config(void)
          {
          GPIO_InitTypeDef GPIO_InitStructure;
          USART_InitTypeDef USART_InitStructure;
          NVIC_InitTypeDef NVIC_InitStructure;
          DMA_InitTypeDef DMA_InitStructure;
          RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
          RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
          RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
          GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 ;
          GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
          GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
          GPIO_Init(GPIOA, &GPIO_InitStructure);
          GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
          GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
          GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
          GPIO_Init(GPIOA, &GPIO_InitStructure);
          GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
          GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
          GPIO_Init(GPIOA, &GPIO_InitStructure);
          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);
          //////////////////中斷的相關(guān)配置////////////////////////////
          NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
          NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
          NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
          NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
          NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
          NVIC_Init(&NVIC_InitStructure);
          //USART_ITConfig(USART2, USART_IT_RXNE, ENABLE); //允許中斷方式
          USART_Cmd(USART2, ENABLE);

          DMA_DeInit(DMA1_Channel6);
          DMA_InitStructure.DMA_PeripheralBaseAddr = 0x40004404;
          DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)USART2_RECEIVE_DATA;
          DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
          DMA_InitStructure.DMA_BufferSize = 512;
          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_Circular;
          DMA_InitStructure.DMA_Priority = DMA_Priority_High;
          DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
          DMA_Init(DMA1_Channel6, &DMA_InitStructure);
          USART_DMACmd(USART2, USART_DMAReq_Rx, ENABLE);
          DMA_Cmd(DMA1_Channel6, ENABLE);
          USART_ITConfig(USART2, USART_IT_IDLE , ENABLE);
          }

          本文引用地址:http://www.ex-cimer.com/article/201612/325187.htm中斷部分:

          void USART2_IRQHandler(void)
          {
          // uint8_t data;
          int i = 0;
          // static u8 usart2_i;
          int DATA_LEN;
          OSIntEnter();
          // if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET)
          // {
          // USART_ClearITPendingBit(USART2,USART_IT_RXNE);
          // data = USART_ReceiveData ( USART2 ) ;
          // // USART_SendData(USART1, data);
          // // printf("%c",data);
          // // usart2_buffer[usart2_i] = data;
          // }
          if(USART_GetITStatus(USART2, USART_IT_IDLE) != RESET)
          {
          DMA_Cmd(DMA1_Channel6, DISABLE);
          i = USART2->DR;

          //防止不必要的錯誤出現(xiàn)
          if( DMA_GetCurrDataCounter(DMA1_Channel6) > 512)
          {
          return;
          }

          DATA_LEN = 512 - DMA_GetCurrDataCounter(DMA1_Channel6);

          for(i=0;i < DATA_LEN;i ++ )
          {
          USART2_SEND_DATA[i] = USART2_RECEIVE_DATA[i];
          }
          usart2_received_data(USART2_SEND_DATA);
          //printf("%s",USART2_SEND_DATA);
          DMA1_Channel6->CNDTR = 512;
          DMA_Cmd(DMA1_Channel6, ENABLE);
          USART_ClearITPendingBit(USART2, USART_IT_IDLE);
          }
          memset(USART2_SEND_DATA,看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();