I am trying to execute AT commands from a Nordic NRF52. I am using the Nordic UART modulewith 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.