stm32f7xx_it.c 22 KB

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