2

I am trying to execute AT commands from a Nordic NRF52. I am using the Nordic UART module with a built-in function called app_uart_put(uint8_t byte) to put AT commands on the UART. The node that receiving the AT commands is a EE-NBIoT module and it triggers on a postfix \r\n. When I run the following code, I get 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);

But I want to make a more reusable code, so I wrote the following writeCommand function.

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);
}

When I run this function as shown below, I get ERROR.

char cmd[] = "CFUN=1";
nrf_delay_ms(1000);
writeCommand(cmd);

Why does not this work? When I look at the outgoing commands, they are equal.

1 Answers1

0

Start by acquiring a large A3 sheet of paper, find a red pen and write 1000 times

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.

...

I had a brief look at the AT command documentation for U-Blox Sara N210, and it seems decent although a bit brief on the introduction part. I suggest reading the V.250 specification first because that is much more thorough. So after writing your 1000 sentences, read this answer, first following the instructions regarding V.250, and then implement something along the given code structure of how to properly handle AT command command/response text.


Of course the first part was meant to be funny, but I am dead serious about the rest; you have some huge AT command knowledge "holes" you must fill. You will not be able have reliable communication until you do. It should not be very difficult, but it will require some effort.

Community
  • 1
  • 1
hlovdal
  • 26,565
  • 10
  • 94
  • 165