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__