SHARE
TWEET

Untitled

a guest Mar 19th, 2020 8 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. //INTERRUPT FILE
  3.  
  4. extern volatile char RxData[10][8];
  5. extern volatile uint8_t RxComplete;
  6. extern volatile uint8_t RxCompleteOneRow;
  7. extern volatile uint8_t TxComplete;
  8.  
  9. //volatile uint32_t tick;
  10. //volatile uint32_t tack;
  11.  
  12. extern volatile uint8_t ColumnRxBuffer;
  13. extern volatile uint8_t RowRxBuffer;
  14. void USART2_IRQHandler(void)
  15. {
  16.     //HAL_UART_IRQHandler(&huart2);
  17.     if(__HAL_UART_GET_IT_SOURCE(&huart2, UART_IT_RXNE))
  18.     {
  19.         if(RowRxBuffer < 9)
  20.         {
  21.             if(ColumnRxBuffer < 7)
  22.             {
  23.                 RxData[RowRxBuffer][ColumnRxBuffer] = (uint8_t)(huart2.Instance->DR & (uint8_t)0xff);
  24.                 ColumnRxBuffer++;
  25.             }
  26.             else
  27.             {
  28.                 RxData[RowRxBuffer][ColumnRxBuffer] = (uint8_t)(huart2.Instance->DR & (uint8_t)0xff);
  29.                 ColumnRxBuffer = 0;
  30.                 if(RowRxBuffer == 0)
  31.                 {
  32.                     RxCompleteOneRow = 1;
  33.                 }
  34.                 RxComplete = 1;
  35.                 __HAL_UART_FLUSH_DRREGISTER(&huart2);
  36.                 RowRxBuffer++;
  37.             }
  38.         }
  39.         else
  40.         {
  41.             if(ColumnRxBuffer < 7)
  42.             {
  43.                 RxData[RowRxBuffer][ColumnRxBuffer] = (uint8_t)(huart2.Instance->DR & (uint8_t)0xff);
  44.                 ColumnRxBuffer++;
  45.             }
  46.             else
  47.             {
  48.                 RxData[RowRxBuffer][ColumnRxBuffer] = (uint8_t)(huart2.Instance->DR & (uint8_t)0xff);
  49.                 ColumnRxBuffer = 0;
  50.                 RxComplete = 1;
  51.                 __HAL_UART_FLUSH_DRREGISTER(&huart2);
  52.                 RowRxBuffer = 0;
  53.             //  tick = 0;
  54.  
  55.             }
  56.         }
  57.     }
  58.     else if(__HAL_UART_GET_IT_SOURCE(&huart2, UART_IT_TC))
  59.     {
  60.         TxComplete = 1;
  61.     }
  62.     return;
  63. }
  64.  
  65. //CONFIG FUNCTION
  66.  
  67. static void MX_USART2_UART_Init(void)
  68. {
  69.  
  70.   huart2.Instance = USART2;
  71.   huart2.Init.BaudRate = 9600;
  72.   huart2.Init.WordLength = UART_WORDLENGTH_8B;
  73.   huart2.Init.StopBits = UART_STOPBITS_1;
  74.   huart2.Init.Parity = UART_PARITY_NONE;
  75.   huart2.Init.Mode = UART_MODE_TX_RX;
  76.   huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  77.   huart2.Init.OverSampling = UART_OVERSAMPLING_16;
  78.   if (HAL_UART_Init(&huart2) != HAL_OK)
  79.   {
  80.     Error_Handler();
  81.   }
  82.  
  83.   __HAL_UART_ENABLE_IT(&huart2, UART_IT_RXNE);
  84.   __HAL_UART_ENABLE_IT(&huart2, UART_IT_TC);
  85.  
  86. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top