From 58dfe5bb9c0bcc3343145bfefc0d6a0f96df3805 Mon Sep 17 00:00:00 2001 From: zouhaitao Date: Wed, 29 Jul 2026 10:16:05 +0800 Subject: [PATCH] =?UTF-8?q?debug:=20=E5=A2=9E=E5=8A=A0=20Loopback=5FTest?= =?UTF-8?q?=20=E7=A1=AC=E4=BB=B6=E7=94=B5=E6=B0=94=E5=9B=9E=E7=8E=AF?= =?UTF-8?q?=E8=87=AA=E6=A3=80=E5=8F=8A=E5=AF=B9=E5=BA=94=E7=9A=84=E8=B0=83?= =?UTF-8?q?=E8=AF=95=E4=B8=B2=E5=8F=A3=E6=8C=87=E4=BB=A4=20'l'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App/main.c | 2 ++ Drivers/rf.c | 43 +++++++++++++++++++++++++++++++++++++++++++ Drivers/rf.h | 5 +++++ 3 files changed, 50 insertions(+) diff --git a/App/main.c b/App/main.c index 9c00c55..2afa5d5 100644 --- a/App/main.c +++ b/App/main.c @@ -150,6 +150,8 @@ void Debug_ProcessCommand(char cmd) RF_DiagnosticMode('t'); // 触发射频连续发射诊断 (绿色爆闪) } else if (cmd == 'r' || cmd == 'R') { RF_DiagnosticMode('r'); // 触发 5 秒射频接收监听诊断 + } else if (cmd == 'l' || cmd == 'L') { + Loopback_Test(); // 触发物理电气回环测试 (短路 P2.1 和 P3.6 自检) } } diff --git a/Drivers/rf.c b/Drivers/rf.c index e6c1f01..730a74c 100644 --- a/Drivers/rf.c +++ b/Drivers/rf.c @@ -355,3 +355,46 @@ void RF_DiagnosticMode(char choice) Uart_SendString("=== RF RX Test End ===\r\n"); } } + +/** + * @brief 电气回环自检测试 (物理短路 P2.1 与 P3.6 自检) + * @details 用户通过短路 P2.1 和 P3.6 来实现 GPIO 的物理连通性自检 + */ +void Loopback_Test(void) +{ + u16 match_count = 0; + u16 i; + + EAXFR = 1; + RF_SetMode(1); // 开启接收芯片 + Delay_ms(100); + + Uart_SendString("Starting RF Hardware Loopback Test (P2.1 -> P3.6)...\r\n"); + Uart_SendString("Please use a metal tweezers to short-circuit P2.1 (Pin 22) and P3.6 (Pin 19)!\r\n"); + + for (i = 0; i < 100; i++) + { + RF_TX_DAT = 1; + Delay_us(500); + if (RF_RX_DATA == 1) match_count++; + + RF_TX_DAT = 0; + Delay_us(500); + if (RF_RX_DATA == 0) match_count++; + } + + Uart_SendString("Loopback Match Count: "); + Uart_SendHex16(match_count); + Uart_SendString("/200\r\n"); + + if (match_count > 150) + { + Uart_SendString("Result: PASS! Pin P2.1 and P3.6 are electrical connected successfully!\r\n"); + } + else + { + Uart_SendString("Result: FAIL! GPIO coupling check failed. Short-circuit the pins and test again.\r\n"); + } + + RF_SetMode(0); // 关断射频 +} diff --git a/Drivers/rf.h b/Drivers/rf.h index fc2ff16..83dd502 100644 --- a/Drivers/rf.h +++ b/Drivers/rf.h @@ -61,4 +61,9 @@ bit EV1527_Decode(u32 *out_addr, u8 *out_data); */ void RF_DiagnosticMode(char choice); +/** + * @brief 电气回环自检测试 (物理短路 P2.1 与 P3.6 自检) + */ +void Loopback_Test(void); + #endif // __RF_H__