Tip / 登入 to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
Translation_Bot
Community Manager
Community Manager
Community Manager

大家好,

在我的初始代碼中,我在主函數中使用 UART_RECEV 和 UART 傳輸函數來傳輸數據。 但它必須使用延遲,以確保沒有公共汽車競爭。

我不想要這種延遲,所以想嘗試中斷。 但我不知道如何觸發中斷。

在附件中是我的項目。

希望你 CAN 改進它。

謝謝

 

int main(void)
{

  DAVE_STATUS_t status;
  status = DAVE_Init();           /* Initialization of DAVE APPs  */
  if (status != DAVE_STATUS_SUCCESS)
  {
    /* Placeholder for error handler code. The while loop below can be replaced with an user error handler. */
    XMC_DEBUG("DAVE APPs initialization failed\n");
  }
    uint8_t send_data[] = {0x1F, 0x08, 0x01, 0x06, 0x41, 0x43, 0x54, 0x34, 0x33, 0x30, 0xAE, 0x04};
uint8_t read_data = 0x00;
    uint8_t read_data2[] = {0x00, 0x00, 0x00, 0x00};

  /* Placeholder for user application code. The while loop below can be replaced with user application code. */
while(1U)
 {
      UART_Receive(&UART_0, &read_data, 1);
      delay_100us();
      if((read_data==0x00)||(read_data==0x1F))
  {
      UART_Receive(&UART_0, &read_data, 1);
      delay_100us();
      if(read_data==0x03)
      {
      read_data = 0x00;
      UART_Receive(&UART_0, read_data2, sizeof(read_data2));
      delay_5ms();
      if((read_data2[0]==0x02)&&(read_data2[1]==0x06)&&(read_data2[2]==0x0B)&&(read_data2[3]==0x04))
      {
delay_100us();
      UART_Transmit(&UART_0, send_data, sizeof(send_data));
      read_data = 0x00;
      }
      }
  }
 }
}

 

3 回應
Translation_Bot
Community Manager
Community Manager
Community Manager

嗨,@lila_young

您 CAN 參考“幫助-幫助內容-DAVE APPs-UART”來了解如何配置UART APP:

Owen_Su_0-1693296944569.png

#include 
 uint8_t data[] = "Infineon Technologies";
 uint8_t rec_data[10];
 int main(void)
 {
   DAVE_STATUS_t status;
   status = DAVE_Init();      /* Initialization of DAVE APPs  */
   if(status == DAVE_STATUS_FAILURE)
   {
     /* Placeholder for error handler code. The while loop below can be replaced with an user error handler */
     XMC_DEBUG(("DAVE Apps initialization failed with status %d\n", status));
     while(1U)
     {
     }
   }

   UART_Transmit(&UART_0, data, sizeof(data) - 1); //Transmit the string "Infineon Technologies".

   while(1U)
   {
   }
   return 1;
 }

 void EndofTransmit()//Callback functin for "End of transmit" event.
 {
  UART_Receive(&UART_0, rec_data, sizeof(rec_data));
 }

 void EndofReceive()//Callback function for "End of receive" event.
 {
  UART_Transmit(&UART_0, rec_data, sizeof(rec_data));
 }

希望這 CAN 幫助你。

BR,

歐文

0
Translation_Bot
Community Manager
Community Manager
Community Manager

謝謝你的回答。 這肯定是一個解決方案。

但這不是我想要的 我不想在 main 函數中調用任何函數。 我希望數據輸入自動觸發接收中斷。

0
lock attach
Attachments are accessible only for community members.
Translation_Bot
Community Manager
Community Manager
Community Manager

嗨,

那麼你 CAN 參考這個附件。這個程序利用中斷來傳輸和接收 UART 數據。 希望這 CAN 幫助你。

BR,

歐文

0