【发布时间】:2018-07-06 01:54:37
【问题描述】:
我正在尝试从Nordic NRF52 执行 AT 命令。我正在使用Nordic UART module 和一个名为app_uart_put(uint8_t byte) 的内置函数将AT 命令放在UART 上。接收 AT 命令的节点是EE-NBIoT module,它在后缀\r\n 上触发。当我运行以下代码时,我得到了 OK。
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);
为什么这不起作用?当我查看传出命令时,它们是相等的。
【问题讨论】:
-
你得到哪个错误?
-
看起来不错。只需将
uint8_t i;更改为size_t i。 -
第一个sn-p发送
AT+CFUN=1,第二个发送AT+CGATT=1对吗? -
\r 在 AT 命令之后应该足够了。 \n 不需要。
-
你听说过数组吗?使用一个来存储你的命令字符串!
标签: c iot uart at-command nrf52