我正在尝试从Nordic NRF52执行 AT 命令。我正在使用带有内置函数的Nordic UART 模块app_uart_put(uint8_t byte)
,该函数调用将 AT 命令放在 UART 上。接收 AT 命令的节点是一个EE-NBIoT 模块,它在 postfix 上触发\r\n
。当我运行以下代码时,我得到了确定。
while (app_uart_put('A') != NRF_SUCCESS);
while (app_uart_put('T') != NRF_SUCCESS);
while (app_uart_put('+') != NRF_SUCCESS);
while (app_uart_put('C') != NRF_SUCCESS);
while (app_uart_put('F') != NRF_SUCCESS);
while (app_uart_put('U') != NRF_SUCCESS);
while (app_uart_put('N') != NRF_SUCCESS);
while (app_uart_put('=') != NRF_SUCCESS);
while (app_uart_put('1') != NRF_SUCCESS);
while (app_uart_put('\r') != NRF_SUCCESS);
while (app_uart_put('\n') != NRF_SUCCESS);
但是我想做一个更可重用的代码,所以我写了下面的writeCommand函数。
void writeCommand(char cmd[])
{
while (app_uart_put('A') != NRF_SUCCESS);
while (app_uart_put('T') != NRF_SUCCESS);
while (app_uart_put('+') != NRF_SUCCESS);
uint8_t i;
for(i = 0; cmd[i] != '\0'; i++){
while (app_uart_put(cmd[i]) != NRF_SUCCESS);
}
while (app_uart_put('\r') != NRF_SUCCESS);
while (app_uart_put('\n') != NRF_SUCCESS);
nrf_delay_ms(100);
}
当我如下所示运行这个函数时,我得到了错误。
char cmd[] = "CFUN=1";
nrf_delay_ms(1000);
writeCommand(cmd);
为什么这不起作用?当我查看传出命令时,它们是相等的。