久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 3548|回復(fù): 1
收起左側(cè)

HAL庫版本的stm32 usart dma空閑中斷接收源碼

[復(fù)制鏈接]
ID:256558 發(fā)表于 2018-2-2 15:56 | 顯示全部樓層 |閱讀模式
分享個stm32單片機(jī)的 usart dma空閑中斷發(fā)送源碼
是基于HAL庫版本的
單片機(jī)源程序如下:
  1. /**
  2.   ******************************************************************************
  3.   * File Name          : main.c
  4.   * Description        : Main program body
  5.   ******************************************************************************
  6.   ** This notice applies to any and all portions of this file
  7.   * that are not between comment pairs USER CODE BEGIN and
  8.   * USER CODE END. Other portions of this file, whether
  9.   * inserted by the user or by software development tools
  10.   * are owned by their respective copyright owners.
  11.   *
  12.   * COPYRIGHT(c) 2018 STMicroelectronics
  13.   *
  14.   * Redistribution and use in source and binary forms, with or without modification,
  15.   * are permitted provided that the following conditions are met:
  16.   *   1. Redistributions of source code must retain the above copyright notice,
  17.   *      this list of conditions and the following disclaimer.
  18.   *   2. Redistributions in binary form must reproduce the above copyright notice,
  19.   *      this list of conditions and the following disclaimer in the documentation
  20.   *      and/or other materials provided with the distribution.
  21.   *   3. Neither the name of STMicroelectronics nor the names of its contributors
  22.   *      may be used to endorse or promote products derived from this software
  23.   *      without specific prior written permission.
  24.   *
  25.   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  26.   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  27.   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  28.   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  29.   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  30.   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  31.   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  32.   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  33.   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  34.   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35.   *
  36.   ******************************************************************************
  37.   */

  38. /* Includes ------------------------------------------------------------------*/
  39. #include "main.h"
  40. #include "stm32f4xx_hal.h"
  41. #include "dma.h"
  42. #include "usart.h"
  43. #include "gpio.h"

  44. /* USER CODE BEGIN Includes */
  45. /* USER CODE END Includes */

  46. /* Private variables ---------------------------------------------------------*/

  47. /* USER CODE BEGIN PV */
  48. /* Private variables ---------------------------------------------------------*/

  49. /* USER CODE END PV */

  50. /* Private function prototypes -----------------------------------------------*/
  51. void SystemClock_Config(void);

  52. /* USER CODE BEGIN PFP */
  53. /* Private function prototypes -----------------------------------------------*/

  54. /* USER CODE END PFP */

  55. /* USER CODE BEGIN 0 */

  56. /* USER CODE END 0 */

  57. int main(void)
  58. {

  59.   /* USER CODE BEGIN 1 */

  60.   /* USER CODE END 1 */

  61.   /* MCU Configuration----------------------------------------------------------*/

  62.   /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  63.   HAL_Init();

  64.   /* USER CODE BEGIN Init */

  65.   /* USER CODE END Init */

  66.   /* Configure the system clock */
  67.   SystemClock_Config();

  68.   /* USER CODE BEGIN SysInit */

  69.   /* USER CODE END SysInit */

  70.   /* Initialize all configured peripherals */
  71.   MX_GPIO_Init();
  72.   MX_DMA_Init();
  73.   MX_USART3_UART_Init();
  74.         

  75.   /* USER CODE BEGIN 2 */
  76. HAL_UART_Receive_DMA(&huart3,Test1.Data_Space,DataSize);
  77. __HAL_UART_ENABLE_IT(&huart3, UART_IT_IDLE);
  78.   /* USER CODE END 2 */

  79.   /* Infinite loop */
  80.   /* USER CODE BEGIN WHILE */
  81.   while (1)
  82.   {
  83.   /* USER CODE END WHILE */

  84.   /* USER CODE BEGIN 3 */
  85. if(Test1.Send_Flag==1 && Test1.Send1==1)
  86. {
  87.    HAL_UART_Transmit_DMA(&huart3, SENDDATA, Test1.RLen);  
  88.          Test1.Send1=0;
  89.          Test1.Send_Flag=0;
  90. }
  91. if(Test1.Send_Flag==1 && Test1.Send1==0)
  92. {
  93.    HAL_UART_Transmit_DMA(&huart3, SENDDATB, Test1.RLen);  
  94.          Test1.Send1=1;
  95.          Test1.Send_Flag=0;

  96. }
  97.   }
  98.   /* USER CODE END 3 */

  99. }

  100. /** System Clock Configuration
  101. */
  102. void SystemClock_Config(void)
  103. {

  104.   RCC_OscInitTypeDef RCC_OscInitStruct;
  105.   RCC_ClkInitTypeDef RCC_ClkInitStruct;

  106.     /**Configure the main internal regulator output voltage
  107.     */
  108.   __HAL_RCC_PWR_CLK_ENABLE();

  109.   __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

  110.     /**Initializes the CPU, AHB and APB busses clocks
  111.     */
  112.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  113.   RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  114.   RCC_OscInitStruct.HSICalibrationValue = 16;
  115.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  116.   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  117.   RCC_OscInitStruct.PLL.PLLM = 8;
  118.   RCC_OscInitStruct.PLL.PLLN = 84;
  119.   RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  120.   RCC_OscInitStruct.PLL.PLLQ = 4;
  121.   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  122.   {
  123.     _Error_Handler(__FILE__, __LINE__);
  124.   }

  125.     /**Initializes the CPU, AHB and APB busses clocks
  126.     */
  127.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  128.                               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  129.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  130.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  131.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  132.   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

  133.   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  134.   {
  135.     _Error_Handler(__FILE__, __LINE__);
  136.   }

  137.     /**Configure the Systick interrupt time
  138.     */
  139.   HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);

  140.     /**Configure the Systick
  141.     */
  142.   HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);

  143.   /* SysTick_IRQn interrupt configuration */
  144.   HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
  145. }

  146. /* USER CODE BEGIN 4 */
  147. void HAL_SYSTICK_Callback(void)
  148. {
  149.         
  150. }
  151. /* USER CODE END 4 */

  152. /**
  153.   * @brief  This function is executed in case of error occurrence.
  154.   * @param  None
  155.   * @retval None
  156.   */
  157. void _Error_Handler(char * file, int line)
  158. {
  159.   /* USER CODE BEGIN Error_Handler_Debug */
  160.   /* User can add his own implementation to report the HAL error return state */
  161.   while(1)
  162.   {
  163.   }
  164.   /* USER CODE END Error_Handler_Debug */
  165. }

  166. #ifdef USE_FULL_ASSERT

  167. /**
  168.    * @brief Reports the name of the source file and the source line number
  169.    * where the assert_param error has occurred.
  170.    * @param file: pointer to the source file name
  171.    * @param line: assert_param error line source number
  172.    * @retval None
  173.    */
  174. void assert_failed(uint8_t* file, uint32_t line)
  175. {
  176.   /* USER CODE BEGIN 6 */
  177.   /* User can add his own implementation to report the file name and line number,
  178.     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  179.   /* USER CODE END 6 */

  180. }


  181. #endif

  182. /**
  183.   * @}
  184.   */

  185. /**
  186.   * @}
  187. */

  188. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
復(fù)制代碼

所有資料51hei提供下載:
F4usart3_test2.rar (523.35 KB, 下載次數(shù): 56)
回復(fù)

使用道具 舉報(bào)

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表
主站蜘蛛池模板: 亚洲欧美一区二区在线观看 | 日韩av一区二区在线观看 | 欧美激情综合 | 麻豆久久| 国产你懂的在线观看 | 91精品国产91久久久久久最新 | 97人澡人人添人人爽欧美 | 麻豆av一区二区三区久久 | 91高清视频在线 | 国产精品久久久亚洲 | 免费精品 | 国产一区二区三区久久久久久久久 | 中文字幕亚洲一区二区三区 | 亚洲日本国产 | 成人精品免费视频 | 成人在线一区二区三区 | 天天干天天爱天天操 | 99热激情| 天天操操操操操 | 国产精品视频在线免费观看 | 99久久精品免费看国产小宝寻花 | a级毛片基地 | 日韩黄色小视频 | 自拍偷拍第一页 | 国产一区二区三区在线免费 | 日本不卡在线观看 | 欧美日韩久久久久 | 中文字幕二区三区 | 国产高清一区二区三区 | 中文字幕一区二区三区日韩精品 | 99热在线免费 | 国产精品一区在线播放 | 国产免费xxx | 91精品久久久久 | 高清av一区| japanhd成人 | 欧洲一区二区三区 | www.yw193.com| 中文字幕不卡在线观看 | 在线一级片 | 日本久久综合网 |