stm32f7xx_it.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file stm32f7xx_it.c
  5. * @brief Interrupt Service Routines.
  6. ******************************************************************************
  7. *
  8. * COPYRIGHT(c) 2019 STMicroelectronics
  9. *
  10. * Redistribution and use in source and binary forms, with or without modification,
  11. * are permitted provided that the following conditions are met:
  12. * 1. Redistributions of source code must retain the above copyright notice,
  13. * this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright notice,
  15. * this list of conditions and the following disclaimer in the documentation
  16. * and/or other materials provided with the distribution.
  17. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  18. * may be used to endorse or promote products derived from this software
  19. * without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  22. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  24. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  25. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  27. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  28. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  29. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. *
  32. ******************************************************************************
  33. */
  34. /* USER CODE END Header */
  35. /* Includes ------------------------------------------------------------------*/
  36. #include "main.h"
  37. #include "Data_deal.h"
  38. #include "stm32f7xx_it.h"
  39. #include "cmsis_os.h"
  40. /* Private includes ----------------------------------------------------------*/
  41. /* USER CODE BEGIN Includes */
  42. /* USER CODE END Includes */
  43. /* Private typedef -----------------------------------------------------------*/
  44. /* USER CODE BEGIN TD */
  45. /* USER CODE END TD */
  46. /* Private define ------------------------------------------------------------*/
  47. /* USER CODE BEGIN PD */
  48. /* USER CODE END PD */
  49. /* Private macro -------------------------------------------------------------*/
  50. /* USER CODE BEGIN PM */
  51. /* USER CODE END PM */
  52. /* Private variables ---------------------------------------------------------*/
  53. /* USER CODE BEGIN PV */
  54. /* USER CODE END PV */
  55. /* Private function prototypes -----------------------------------------------*/
  56. /* USER CODE BEGIN PFP */
  57. /* USER CODE END PFP */
  58. /* Private user code ---------------------------------------------------------*/
  59. /* USER CODE BEGIN 0 */
  60. #include "usart.h"
  61. #include "tim.h"
  62. #include "KeySlave485.h"
  63. #include "Dwin.h"
  64. #include "Elec_Seal.h"
  65. #define Screen_SleepTime 1800 //3600// 60分钟 3600S/60=10min
  66. #define RE_Sealloading_Time 60//自动施封时间,单位秒
  67. uint16_t Sleep_Count=0;
  68. uint16_t Count_LED5=0;
  69. uint16_t Read_Collect485_Count;
  70. uint16_t Auto_unload_clear_cnt=0;
  71. uint8_t Auto_Seal_Exti_cnt = 0;
  72. uint32_t overflow_cnt=0;//静电控制器脉冲输入溢出次数
  73. uint32_t Pro_overflow_cnt =0;
  74. uint16_t Auto_Seal_cnt_Time = 0;
  75. extern volatile uint8_t screen_delay;
  76. /* USER CODE END 0 */
  77. /* External variables --------------------------------------------------------*/
  78. extern TIM_HandleTypeDef htim2;
  79. extern TIM_HandleTypeDef htim6;
  80. extern DMA_HandleTypeDef hdma_uart4_rx;
  81. extern DMA_HandleTypeDef hdma_usart1_rx;
  82. extern DMA_HandleTypeDef hdma_usart2_rx;
  83. extern DMA_HandleTypeDef hdma_usart3_rx;
  84. extern UART_HandleTypeDef huart4;
  85. extern UART_HandleTypeDef huart1;
  86. extern UART_HandleTypeDef huart2;
  87. extern UART_HandleTypeDef huart3;
  88. extern TIM_HandleTypeDef htim1;
  89. /* USER CODE BEGIN EV */
  90. /* USER CODE END EV */
  91. /******************************************************************************/
  92. /* Cortex-M7 Processor Interruption and Exception Handlers */
  93. /******************************************************************************/
  94. /**
  95. * @brief This function handles Non maskable interrupt.
  96. */
  97. void NMI_Handler(void)
  98. {
  99. /* USER CODE BEGIN NonMaskableInt_IRQn 0 */
  100. /* USER CODE END NonMaskableInt_IRQn 0 */
  101. /* USER CODE BEGIN NonMaskableInt_IRQn 1 */
  102. /* USER CODE END NonMaskableInt_IRQn 1 */
  103. }
  104. /**
  105. * @brief This function handles Hard fault interrupt.
  106. */
  107. void HardFault_Handler(void)
  108. {
  109. /* USER CODE BEGIN HardFault_IRQn 0 */
  110. if (CoreDebug->DHCSR & 1) { //check C_DEBUGEN == 1 -> Debugger Connected
  111. __breakpoint(0); // halt program execution here
  112. }
  113. /* USER CODE END HardFault_IRQn 0 */
  114. while (1)
  115. {
  116. /* USER CODE BEGIN W1_HardFault_IRQn 0 */
  117. /* USER CODE END W1_HardFault_IRQn 0 */
  118. }
  119. }
  120. /**
  121. * @brief This function handles Memory management fault.
  122. */
  123. void MemManage_Handler(void)
  124. {
  125. /* USER CODE BEGIN MemoryManagement_IRQn 0 */
  126. /* USER CODE END MemoryManagement_IRQn 0 */
  127. while (1)
  128. {
  129. /* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */
  130. /* USER CODE END W1_MemoryManagement_IRQn 0 */
  131. }
  132. }
  133. /**
  134. * @brief This function handles Pre-fetch fault, memory access fault.
  135. */
  136. void BusFault_Handler(void)
  137. {
  138. /* USER CODE BEGIN BusFault_IRQn 0 */
  139. /* USER CODE END BusFault_IRQn 0 */
  140. while (1)
  141. {
  142. /* USER CODE BEGIN W1_BusFault_IRQn 0 */
  143. /* USER CODE END W1_BusFault_IRQn 0 */
  144. }
  145. }
  146. /**
  147. * @brief This function handles Undefined instruction or illegal state.
  148. */
  149. void UsageFault_Handler(void)
  150. {
  151. /* USER CODE BEGIN UsageFault_IRQn 0 */
  152. /* USER CODE END UsageFault_IRQn 0 */
  153. while (1)
  154. {
  155. /* USER CODE BEGIN W1_UsageFault_IRQn 0 */
  156. /* USER CODE END W1_UsageFault_IRQn 0 */
  157. }
  158. }
  159. /**
  160. * @brief This function handles Debug monitor.
  161. */
  162. void DebugMon_Handler(void)
  163. {
  164. /* USER CODE BEGIN DebugMonitor_IRQn 0 */
  165. /* USER CODE END DebugMonitor_IRQn 0 */
  166. /* USER CODE BEGIN DebugMonitor_IRQn 1 */
  167. /* USER CODE END DebugMonitor_IRQn 1 */
  168. }
  169. /******************************************************************************/
  170. /* STM32F7xx Peripheral Interrupt Handlers */
  171. /* Add here the Interrupt Handlers for the used peripherals. */
  172. /* For the available peripheral interrupt handler names, */
  173. /* please refer to the startup file (startup_stm32f7xx.s). */
  174. /******************************************************************************/
  175. /**
  176. * @brief This function handles DMA1 stream1 global interrupt.
  177. */
  178. void DMA1_Stream1_IRQHandler(void)
  179. {
  180. /* USER CODE BEGIN DMA1_Stream1_IRQn 0 */
  181. /* USER CODE END DMA1_Stream1_IRQn 0 */
  182. HAL_DMA_IRQHandler(&hdma_usart3_rx);
  183. /* USER CODE BEGIN DMA1_Stream1_IRQn 1 */
  184. /* USER CODE END DMA1_Stream1_IRQn 1 */
  185. }
  186. /**
  187. * @brief This function handles DMA1 stream2 global interrupt.
  188. */
  189. void DMA1_Stream2_IRQHandler(void)
  190. {
  191. /* USER CODE BEGIN DMA1_Stream2_IRQn 0 */
  192. /* USER CODE END DMA1_Stream2_IRQn 0 */
  193. ;// HAL_DMA_IRQHandler(&hdma_uart4_rx);
  194. /* USER CODE BEGIN DMA1_Stream2_IRQn 1 */
  195. /* USER CODE END DMA1_Stream2_IRQn 1 */
  196. }
  197. /**
  198. * @brief This function handles DMA1 stream5 global interrupt.
  199. */
  200. void DMA1_Stream5_IRQHandler(void)
  201. {
  202. /* USER CODE BEGIN DMA1_Stream5_IRQn 0 */
  203. /* USER CODE END DMA1_Stream5_IRQn 0 */
  204. HAL_DMA_IRQHandler(&hdma_usart2_rx);
  205. /* USER CODE BEGIN DMA1_Stream5_IRQn 1 */
  206. /* USER CODE END DMA1_Stream5_IRQn 1 */
  207. }
  208. /**
  209. * @brief This function handles TIM1 update interrupt and TIM10 global interrupt.
  210. */
  211. int usart_rx_len;
  212. int delay_ti;
  213. int delay_usart1;
  214. int rs485_rts_delay;
  215. int rs455_1rts_delay;
  216. void TIM1_UP_TIM10_IRQHandler(void)
  217. {
  218. /* USER CODE BEGIN TIM1_UP_TIM10_IRQn 0 */
  219. /* USER CODE END TIM1_UP_TIM10_IRQn 0 */
  220. HAL_TIM_IRQHandler(&htim1);
  221. if(screen_delay)
  222. {
  223. --screen_delay;
  224. }
  225. if(delay_ti)
  226. {
  227. --delay_ti;
  228. if(delay_ti==0)
  229. {
  230. usart2_rx_flag = 1;
  231. rx2_len = usart_rx_len;
  232. usart_rx_len=0;
  233. }
  234. }
  235. if(delay_usart1)
  236. {
  237. --delay_usart1;
  238. if(delay_usart1==0)
  239. {
  240. if(rx1_len)
  241. usart1_rx_flag = 1;
  242. }
  243. }
  244. #if 0
  245. if(rs485_rts_delay)
  246. {
  247. --rs485_rts_delay;
  248. if(rs485_rts_delay==0)
  249. TerminalSlave485_TX_Set(0);
  250. }
  251. if(rs455_1rts_delay)
  252. {
  253. --rs455_1rts_delay;
  254. if(rs455_1rts_delay==0)
  255. CollectMaster485_TX_Set(0); //设置为接收模式
  256. }
  257. #endif
  258. ++circle_send;
  259. /* USER CODE BEGIN TIM1_UP_TIM10_IRQn 1 */
  260. /* USER CODE END TIM1_UP_TIM10_IRQn 1 */
  261. }
  262. /**
  263. * @brief This function handles TIM2 global interrupt.
  264. */
  265. extern SDateTime m_datetime;
  266. void TIM2_IRQHandler(void)
  267. {
  268. /* USER CODE BEGIN TIM2_IRQn 0 */
  269. Sleep_Count++;
  270. Read_Collect485_Count++;
  271. ++m_datetime.msec;
  272. if(m_datetime.msec>=1000)
  273. {
  274. m_datetime.msec=0;
  275. ++m_datetime.sec;
  276. if(m_datetime.sec>=60)
  277. {
  278. m_datetime.sec=0;
  279. ++m_datetime.min;
  280. if(m_datetime.min>=60)
  281. {
  282. m_datetime.min=0;
  283. ++m_datetime.hour;
  284. if(m_datetime.hour>=24)
  285. {
  286. m_datetime.hour=0;
  287. ++m_datetime.day;
  288. }
  289. }
  290. }
  291. }
  292. //打印机定时器
  293. if(tmrForPrinter>0)
  294. tmrForPrinter--;
  295. //任何按键按下定时器
  296. if(tmrForKeyPad>0)
  297. tmrForKeyPad--;
  298. //远程标定模式定时器
  299. if(tmrForRemoteCali>0)
  300. tmrForRemoteCali--;
  301. //手工输入温度之后的定时器
  302. if(tmrForTemp_ManualInput>0)
  303. tmrForTemp_ManualInput--;
  304. if(Sleep_Count>=1000)
  305. {
  306. Sleep_Count=0;
  307. Sleep_Timer_cnt3++;
  308. Auto_Seal_Exti_cnt++;
  309. StartUpdate_Screen_Flag=True;
  310. if(usart_timeout)
  311. {
  312. ++usart_timesec;
  313. }
  314. if(Sleep_Timer_cnt3>=Screen_SleepTime)
  315. {
  316. if(Lcd_sleep_flag!=1)
  317. Lcd_sleep_flag=1;
  318. Sleep_Timer_cnt3=0;
  319. }
  320. if(Auto_Seal_Exti_cnt>=5)//5S
  321. {
  322. Auto_Seal_Exti_cnt = 0;
  323. if(Pro_overflow_cnt!=overflow_cnt)
  324. {
  325. Auto_Seal_cnt_Time =0;
  326. Pro_overflow_cnt = overflow_cnt;//防溢流静电控制器连接中
  327. Full_Oil_allinfo.Start_Full_flag =1;//静电控制器插入,开始装油
  328. Full_Oil_allinfo.Start_Decrease_flag =0;
  329. Full_Oil_allinfo.Auto_full_oil_mode =1;//自动模式
  330. }
  331. else
  332. {
  333. overflow_cnt = 0;//防溢流静电控制器断开中
  334. Pro_overflow_cnt = 0;
  335. }
  336. }
  337. if((Config_info_all.Config_fun_id&0x01)==0x01)//开启自动施封功能
  338. {
  339. if((overflow_cnt == 0)&&(Full_Oil_allinfo.Start_Full_flag ==1))
  340. {
  341. Auto_Seal_cnt_Time++;
  342. if(Auto_Seal_cnt_Time>Config_info_all.Auto_Seal_Time)//自动施封
  343. {
  344. Auto_Seal_cnt_Time =0;
  345. Full_Oil_allinfo.Start_Seal_flag =1;//开始施封
  346. }
  347. }
  348. }
  349. }
  350. if(Read_Collect485_Count>=READ_COLLECT_INTERVAL)//500
  351. {
  352. Read_Collect485_Count=0;
  353. Read_Collect485_Flag=True;
  354. }
  355. if(Auto_unload_clear_info_flag == 1)//计数10S
  356. {
  357. Auto_unload_clear_cnt++;
  358. if(Auto_unload_clear_cnt>=10000)//5000 =5s
  359. {
  360. Auto_unload_clear_info_flag = 0;
  361. Auto_unload_clear_cnt = 0;
  362. Auto_unload_clear_start_flag = 1;
  363. }
  364. }
  365. /* USER CODE END TIM2_IRQn 0 */
  366. HAL_TIM_IRQHandler(&htim2);
  367. /* USER CODE BEGIN TIM2_IRQn 1 */
  368. /* USER CODE END TIM2_IRQn 1 */
  369. }
  370. /**
  371. * @brief This function handles USART1 global interrupt.
  372. */
  373. void USART1_IRQHandler(void)
  374. {
  375. /* USER CODE BEGIN USART1_IRQn 0 */
  376. //HAL_UART_IRQHandler(&huart1);
  377. uint32_t isrflags = huart1.Instance->ISR;
  378. uint32_t cr1its = READ_REG(huart1.Instance->CR1);
  379. if(__HAL_UART_GET_IT(&huart1,UART_IT_RXNE) && __HAL_UART_GET_FLAG(&huart1, UART_FLAG_RXNE))
  380. {
  381. __HAL_UART_CLEAR_IT(&huart1,UART_FLAG_RXNE);
  382. rx1_len %= 1024;
  383. USART1_RX_BUF[rx1_len] = huart1.Instance->RDR;
  384. rx1_len++;
  385. delay_usart1=3;
  386. }
  387. if (((cr1its & USART_CR1_TXEIE) != RESET) && __HAL_UART_GET_FLAG(&huart1, UART_FLAG_TXE))
  388. {
  389. __HAL_UART_CLEAR_IT(&huart1,UART_FLAG_TXE);
  390. if (huart1.pTxBuffPtr)
  391. {
  392. huart1.Instance->TDR = (huart1.pTxBuffPtr[huart1.TxXferCount++] & (uint8_t)0xFFU);
  393. if (huart1.TxXferCount >= huart1.TxXferSize)
  394. {
  395. /* Disable the UART Transmit Data Register Empty Interrupt */
  396. CLEAR_BIT(huart1.Instance->CR1, USART_CR1_TXEIE);
  397. //__HAL_UART_DISABLE_IT(&huart1,UART_IT_TXE);
  398. /* Enable the UART Transmit Complete Interrupt */
  399. SET_BIT(huart1.Instance->CR1, USART_CR1_TCIE);
  400. //__HAL_UART_ENABLE_IT(&huart1,UART_IT_TC);
  401. }
  402. //else
  403. }
  404. }
  405. else if(((isrflags & UART_FLAG_TC)) && ((cr1its & USART_CR1_TCIE) != RESET))
  406. {
  407. TerminalSlave485_TX_Set(0);
  408. __HAL_UART_DISABLE_IT(&huart1,UART_IT_TC);
  409. huart1.gState = HAL_UART_STATE_READY;
  410. }
  411. /* if(__HAL_UART_GET_FLAG(&huart1,UART_FLAG_IDLE))
  412. {
  413. UsartReceive_IDLE(&huart1);
  414. }*/
  415. /* USER CODE END USART1_IRQn 0 */
  416. // HAL_UART_IRQHandler(&huart1);
  417. /* USER CODE BEGIN USART1_IRQn 1 */
  418. if(__HAL_UART_GET_FLAG(&huart1,UART_FLAG_ORE))
  419. {
  420. __HAL_UART_CLEAR_OREFLAG(&huart1);
  421. //taskENTER_CRITICAL();
  422. // HAL_UART_MspDeInit(&huart1);
  423. //HAL_UART_MspInit(&huart1);
  424. //taskEXIT_CRITICAL();
  425. }
  426. __HAL_UART_CLEAR_IT(&huart1,isrflags);
  427. /* USER CODE END USART1_IRQn 1 */
  428. }
  429. /**
  430. * @brief This function handles USART2 global interrupt.
  431. */
  432. void USART2_IRQHandler(void)
  433. {
  434. /* USER CODE BEGIN USART2_IRQn 0 */
  435. uint32_t isrflags = huart2.Instance->ISR;
  436. uint32_t cr1its = READ_REG(huart2.Instance->CR1);
  437. /* HAL_UART_IRQHandler(&huart2);
  438. if(__HAL_UART_GET_FLAG(&huart2,UART_FLAG_IDLE))
  439. {
  440. UsartReceive_IDLE(&huart2);
  441. }*/
  442. if(__HAL_UART_GET_IT(&huart2,UART_IT_RXNE) && __HAL_UART_GET_FLAG(&huart2, UART_FLAG_RXNE))
  443. {
  444. __HAL_UART_CLEAR_IT(&huart2,UART_FLAG_RXNE);
  445. usart_rx_len %= Uart2_BUF_SIZE;
  446. USART2_RX_BUF[usart_rx_len] = huart2.Instance->RDR;
  447. usart_rx_len++;
  448. delay_ti=3;
  449. }
  450. /*
  451. 中断发送
  452. zhuzl 20211215 add
  453. */
  454. if (((cr1its & USART_CR1_TXEIE) != RESET) && __HAL_UART_GET_FLAG(&huart2, UART_FLAG_TXE))
  455. {
  456. __HAL_UART_CLEAR_IT(&huart2,UART_FLAG_TXE);
  457. if (huart2.pTxBuffPtr)
  458. {
  459. huart2.Instance->TDR = (huart2.pTxBuffPtr[huart2.TxXferCount++] & (uint8_t)0xFFU);
  460. if (huart2.TxXferCount >= huart2.TxXferSize)
  461. {
  462. /* Disable the UART Transmit Data Register Empty Interrupt */
  463. CLEAR_BIT(huart2.Instance->CR1, USART_CR1_TXEIE);
  464. /* Enable the UART Transmit Complete Interrupt */
  465. SET_BIT(huart2.Instance->CR1, USART_CR1_TCIE);
  466. }
  467. }
  468. }
  469. else if(((isrflags & UART_FLAG_TC)) && ((cr1its & USART_CR1_TCIE) != RESET))
  470. {
  471. CollectMaster485_TX_Set(0); //设置为接收模式
  472. huart2.gState = HAL_UART_STATE_READY;
  473. __HAL_UART_DISABLE_IT(&huart2,UART_IT_TC);
  474. }
  475. //20210107李伟添加
  476. //if(__HAL_UART_GET_FLAG(&huart2,UART_FLAG_ORE))
  477. {
  478. // __HAL_UART_CLEAR_OREFLAG(&huart2);
  479. }
  480. if((__HAL_UART_GET_FLAG(&huart2, UART_FLAG_ORE) != RESET))
  481. {
  482. //i = UART2->ISR; //清除状态寄存器SR,读取SR寄存器可以实现清除SR寄存器的功能
  483. //i = UART2->RDR; //读取数据寄存器中的数据
  484. //i = hdma_uart4_rx.Instance->NDTR;
  485. __HAL_UART_CLEAR_OREFLAG(&huart2);
  486. //HAL_DMA_DeInit(&hdma_uart4_rx);
  487. // HAL_UART_MspInit(&huart2);
  488. //HAL_UART_Receive_DMA(&huart4, USART_RX_BUF,BUF_SIZE);
  489. }
  490. __HAL_UART_CLEAR_IT(&huart2,isrflags);
  491. /* USER CODE END USART2_IRQn 0 */
  492. // HAL_UART_IRQHandler(&huart2);
  493. /* USER CODE BEGIN USART2_IRQn 1 */
  494. /* USER CODE END USART2_IRQn 1 */
  495. }
  496. /**
  497. * @brief This function handles USART3 global interrupt.
  498. */
  499. int usart3_rx_len;
  500. void USART3_IRQHandler(void)
  501. {
  502. uint32_t isrflags = huart3.Instance->ISR;
  503. uint32_t cr1its = READ_REG(huart3.Instance->CR1);
  504. /* USER CODE BEGIN USART3_IRQn 0 */
  505. //HAL_UART_IRQHandler(&huart3);
  506. /* if(__HAL_UART_GET_FLAG(&huart3,UART_FLAG_IDLE))
  507. {
  508. UsartReceive_IDLE(&huart3);
  509. }*/
  510. if(__HAL_UART_GET_IT(&huart3,UART_IT_RXNE) && __HAL_UART_GET_FLAG(&huart3, UART_FLAG_RXNE))
  511. {
  512. __HAL_UART_CLEAR_IT(&huart3,UART_FLAG_RXNE);
  513. usart3_rx_len %= 128;
  514. USART3_RX_BUF[usart3_rx_len] = huart3.Instance->RDR;
  515. usart3_rx_len++;
  516. // delay_ti=5;
  517. }
  518. /*
  519. 中断发送
  520. zhuzl 20211215 add
  521. */
  522. if (((cr1its & USART_CR1_TXEIE) != RESET) && __HAL_UART_GET_FLAG(&huart3, UART_FLAG_TXE))
  523. {
  524. if (huart3.pTxBuffPtr)
  525. {
  526. huart3.Instance->TDR = (huart3.pTxBuffPtr[huart3.TxXferCount++] & (uint8_t)0xFFU);
  527. if (huart3.TxXferCount >= huart3.TxXferSize)
  528. {
  529. //__HAL_UART_CLEAR_IT(&huart3,UART_FLAG_TXE);
  530. CLEAR_BIT(huart3.Instance->CR1, USART_CR1_TXEIE);
  531. /* Enable the UART Transmit Complete Interrupt */
  532. SET_BIT(huart3.Instance->CR1, USART_CR1_TCIE);
  533. }
  534. }
  535. }
  536. else if(((isrflags & UART_FLAG_TC)) && ((cr1its & USART_CR1_TCIE) != RESET))
  537. {
  538. ScreenMaster485_TX_Set(0);
  539. CLEAR_BIT(huart3.Instance->CR1, USART_CR1_TCIE);
  540. huart3.gState = HAL_UART_STATE_READY;
  541. screen_delay=40;
  542. }
  543. //20210107李伟添加
  544. if(__HAL_UART_GET_FLAG(&huart3,UART_FLAG_ORE))
  545. {
  546. __HAL_UART_CLEAR_OREFLAG(&huart3);
  547. HAL_UART_MspInit(&huart3);
  548. }
  549. __HAL_UART_CLEAR_IT(&huart3,isrflags);
  550. /* USER CODE END USART3_IRQn 0 */
  551. // HAL_UART_IRQHandler(&huart3);
  552. /* USER CODE BEGIN USART3_IRQn 1 */
  553. /* USER CODE END USART3_IRQn 1 */
  554. }
  555. /**
  556. * @brief This function handles UART4 global interrupt.
  557. */
  558. void UART4_IRQHandler(void)
  559. {
  560. /* USER CODE BEGIN UART4_IRQn 0 */
  561. uint32_t i = 0;
  562. uint32_t isrflags = huart4.Instance->ISR;
  563. uint32_t cr1its = READ_REG(huart4.Instance->CR1);
  564. //HAL_UART_IRQHandler(&huart4);
  565. if (__HAL_UART_GET_FLAG(&huart4, UART_FLAG_IDLE))
  566. {
  567. // UsartReceive_IDLE(&huart4);
  568. __HAL_UART_CLEAR_IDLEFLAG(&huart4);
  569. //__HAL_UART_CLEAR_IDLEFLAG(UART4);
  570. // i = huart4->Instance->ISR;
  571. // i = huart4->Instance->RDR;
  572. // i = hdma_uart4_rx.Instance->NDTR;
  573. // HAL_UART_DMAStop(huart);
  574. // HAL_UART_Receive_DMA(&huart4, USART_RX_BUF,BUF_SIZE);
  575. //此处处理数据,主要是拷贝和置位标志位 //
  576. // memcpy(UART4_RX_BUF, USART_RX_BUF, (BUF_SIZE - i));
  577. usart4_rx_flag = 1;
  578. rx4_len = uart4RxCounter - 0;
  579. uart4RxCounter = 0;
  580. // __nop();
  581. // rx4_len = BUF_SIZE - i;//实际接收到的有用数据
  582. // memset(USART_RX_BUF, 0x00, BUF_SIZE);
  583. }
  584. if ((__HAL_UART_GET_FLAG(&huart4, UART_FLAG_ORE) != RESET))
  585. {
  586. i = UART4->ISR; //清除状态寄存器SR,读取SR寄存器可以实现清除SR寄存器的功能
  587. i = UART4->RDR; //读取数据寄存器中的数据
  588. // i = hdma_uart4_rx.Instance->NDTR;
  589. __HAL_UART_CLEAR_OREFLAG(&huart4);
  590. // HAL_DMA_DeInit(&hdma_uart4_rx);
  591. HAL_UART_MspInit(&huart4);
  592. // HAL_UART_Receive_DMA(&huart4, USART_RX_BUF,BUF_SIZE);
  593. }
  594. if (__HAL_UART_GET_FLAG(&huart4, UART_FLAG_RXNE)) //接收中断
  595. {
  596. i = UART4->RDR;
  597. // sMyUart4.rxBuf[sMyUart4.rxTotal++] = i;
  598. UART4_RX_BUF[uart4RxCounter++] = i;
  599. //__nop();
  600. if (uart4RxCounter >= Uart1_BUF_SIZE - 1)
  601. {
  602. uart4RxCounter = 0; //避免溢出错误
  603. }
  604. //__HAL_UART_CLEAR_OREFLAG(UART4, UART_IT_RXNE);读取DR自动清零 不需要手动清零
  605. }
  606. if (((cr1its & USART_CR1_TXEIE) != RESET) && __HAL_UART_GET_FLAG(&huart4, UART_FLAG_TXE))
  607. {
  608. if (huart4.pTxBuffPtr)
  609. {
  610. huart4.Instance->TDR = (huart4.pTxBuffPtr[huart4.TxXferCount++] & (uint8_t)0xFFU);
  611. if (huart4.TxXferCount >= huart4.TxXferSize)
  612. {
  613. //__HAL_UART_CLEAR_IT(&huart3,UART_FLAG_TXE);
  614. CLEAR_BIT(huart4.Instance->CR1, USART_CR1_TXEIE);
  615. /* Enable the UART Transmit Complete Interrupt */
  616. SET_BIT(huart4.Instance->CR1, USART_CR1_TCIE);
  617. }
  618. }
  619. }
  620. else if (((isrflags & UART_FLAG_TC)) && ((cr1its & USART_CR1_TCIE) != RESET))
  621. {
  622. KeySlave485_TX_Set(0);
  623. CLEAR_BIT(huart4.Instance->CR1, USART_CR1_TCIE);
  624. huart4.gState = HAL_UART_STATE_READY;
  625. }
  626. /* USER CODE END UART4_IRQn 0 */
  627. // HAL_UART_IRQHandler(&huart4);
  628. /* USER CODE BEGIN UART4_IRQn 1 */
  629. //
  630. // __HAL_UART_CLEAR_PEFLAG(&huart4);
  631. //
  632. // __HAL_UART_CLEAR_FEFLAG(&huart4);
  633. //
  634. // __HAL_UART_CLEAR_OREFLAG(&huart4);
  635. //20210107李伟添加
  636. /*if(__HAL_UART_GET_FLAG(&huart4,UART_FLAG_ORE))
  637. {
  638. __HAL_UART_CLEAR_OREFLAG(&huart4);
  639. }*/
  640. __HAL_UART_CLEAR_IT(&huart4,isrflags);
  641. /* USER CODE END UART4_IRQn 1 */
  642. }
  643. /**
  644. * @brief This function handles TIM6 global interrupt, DAC1 and DAC2 underrun error interrupts.
  645. */
  646. void TIM6_DAC_IRQHandler(void)
  647. {
  648. /* USER CODE BEGIN TIM6_DAC_IRQn 0 */
  649. // Count_LED4++;
  650. // if(Count_LED4>=500)
  651. // {
  652. // Count_LED4=0;
  653. // HAL_GPIO_TogglePin(GPIOE,LED4_Pin);
  654. // }
  655. /* USER CODE END TIM6_DAC_IRQn 0 */
  656. HAL_TIM_IRQHandler(&htim6);
  657. /* USER CODE BEGIN TIM6_DAC_IRQn 1 */
  658. /* USER CODE END TIM6_DAC_IRQn 1 */
  659. }
  660. /**
  661. * @brief This function handles DMA2 stream2 global interrupt.
  662. */
  663. void DMA2_Stream2_IRQHandler(void)
  664. {
  665. /* USER CODE BEGIN DMA2_Stream2_IRQn 0 */
  666. /* USER CODE END DMA2_Stream2_IRQn 0 */
  667. HAL_DMA_IRQHandler(&hdma_usart1_rx);
  668. /* USER CODE BEGIN DMA2_Stream2_IRQn 1 */
  669. /* USER CODE END DMA2_Stream2_IRQn 1 */
  670. }
  671. /* USER CODE BEGIN 1 */
  672. /**
  673. * @brief This function handles EXTI line0 interrupt.
  674. */
  675. void EXTI0_IRQHandler(void)
  676. {
  677. /* USER CODE BEGIN EXTI0_IRQn 0 */
  678. /* USER CODE END EXTI0_IRQn 0 */
  679. HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_0);
  680. /* USER CODE BEGIN EXTI0_IRQn 1 */
  681. /* USER CODE END EXTI0_IRQn 1 */
  682. }
  683. /**
  684. * @brief This function handles EXTI line[15:10] interrupts.
  685. */
  686. //void EXTI15_10_IRQHandler(void)
  687. //{
  688. // /* USER CODE BEGIN EXTI15_10_IRQn 0 */
  689. // /* USER CODE END EXTI15_10_IRQn 0 */
  690. // HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_10);
  691. // HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_11);
  692. // HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_12);
  693. // HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_13);
  694. // /* USER CODE BEGIN EXTI15_10_IRQn 1 */
  695. // /* USER CODE END EXTI15_10_IRQn 1 */
  696. //}
  697. //void EXTI15_10_IRQHandler(void)
  698. //{
  699. // HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_13); //调用中断处理公用函数
  700. //}
  701. void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
  702. {
  703. /* NOTE: This function Should not be modified, when the callback is needed,
  704. the HAL_GPIO_EXTI_Callback could be implemented in the user file
  705. */
  706. switch(GPIO_Pin)
  707. {
  708. case GPIO_PIN_0: overflow_cnt++;break;
  709. // case GPIO_PIN_10:LED1_Toggle();break;
  710. // case GPIO_PIN_11:LED2_Toggle();break;
  711. // case GPIO_PIN_12:LED3_Toggle();break;
  712. // case GPIO_PIN_13:LED3_Toggle();break;
  713. default:break;
  714. }
  715. }
  716. /* USER CODE END 1 */
  717. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/