gpt4 book ai didi

c - for 循环中的 AT 命令

转载 作者:太空宇宙 更新时间:2023-11-03 23:59:17 28 4
gpt4 key购买 nike

我正在尝试从 Nordic NRF52 执行 AT 命令.我正在使用 Nordic UART module使用名为 app_uart_put(uint8_t byte) 的内置函数将 AT 命令放在 UART 上。接收 AT 命令的节点是一个 EE-NBIoT module它在后缀 \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);

为什么这行不通?当我查看传出命令时,它们是相等的。

最佳答案

先拿一张大A3纸,找一支红笔写1000遍

I will never use nrf_delay_ms as a substitute for reading and parsing responses from a modem.

I will never use nrf_delay_ms as a substitute for reading and parsing responses from a modem.

I will never use nrf_delay_ms as a substitute for reading and parsing responses from a modem.

I will never use nrf_delay_ms as a substitute for reading and parsing responses from a modem.

I will never use nrf_delay_ms as a substitute for reading and parsing responses from a modem.

...

我简单看了下AT command documentation for U-Blox Sara N210 ,虽然介绍部分有点简短,但看起来不错。我建议先阅读 V.250 规范,因为它更全面。所以在写完 1000 个句子后,阅读 this answer , 首先按照有关 V.250 的说明进行操作,然后根据给定的代码结构实现一些有关如何正确处理 AT 命令命令/响应文本的内容。


当然,第一部分是为了搞笑,但我对其余部分非常认真;您必须填补一些巨大的 AT 命令知识“漏洞”。除非您这样做,否则您将无法进行可靠的通信。这应该不是很困难,但需要一些努力。

关于c - for 循环中的 AT 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51188339/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com