This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

UART shows strange value

Hi Devzone!

I'm using uart to send AT commands to LTE modem.

but when I send AT commands the response is quite strange, and I think the command is sent twice. I don't know why.

The below image is about a right response when I send AT command with PUTTY to modem directly.

and this image is about s strange response when I send AT command at the nRF52840.

The whole code is below

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/**
* Copyright (c) 2014 - 2019, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

What is the problem, and how can I fix it?

Best regards,

Baek

Parents
  • Hi,

    You might want to remove the printf() calls, as these are also sent over the UART.

    Also check if this modem expects both '\r' and '\n' (new line and carriage return) to be added to the commands.

    In uart_event_handle() you use printf() to print the reply from the modem over UART, so you are then sending the reply back to the modem ? If you want to print the reply, use NRF_LOG_INFO() with Segger RTT backend instead. If you use SES, the RTT logs are printed in the SES terminal. (note that you might need to set NRF_FPRINTF_FLAG_AUTOMATIC_CR_ON_LF_ENABLED to 0 in sdk_config.h to show the log correctly).

  • Plus, the response syntax is <CR><LF><response><CR><LF>.

  • Could you try to move the lm5_send(send_data, sizeof(send_data)); function call to above the "for (;;)" main loop, and see if it makes any difference ?

Reply
  • Could you try to move the lm5_send(send_data, sizeof(send_data)); function call to above the "for (;;)" main loop, and see if it makes any difference ?

Children
  • Hi Sigurd!

    sorry the fpu_fft had the problem. It was not stable so when the hardfault error occurs the device was reset again and again.

    When I move away the fpu_fft code, It prints the response only once. but the response is still looks strange.

    now it looks like this.

    It is also same when I move the function to the above of for(;;)

  • zester926 said:
    now it looks like this.

     Is this the output from PuTTY or Segger RTT ?

    Could you try to remove these lines:

     printf("\r\ntest\r\n"); and  printf("\r\nUART started.\r\n"); 

    How does the code look like now ? Could you post the main.c and sdk_config.h file ?

  • Hi Sigurd!

    This is the output from RTT.

    yep I removed both printfs but, It is not changed. still same.

    Here is my main.c

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    /**
    * Copyright (c) 2014 - 2019, Nordic Semiconductor ASA
    *
    * All rights reserved.
    *
    * Redistribution and use in source and binary forms, with or without modification,
    * are permitted provided that the following conditions are met:
    *
    * 1. Redistributions of source code must retain the above copyright notice, this
    * list of conditions and the following disclaimer.
    *
    * 2. Redistributions in binary form, except as embedded into a Nordic
    * Semiconductor ASA integrated circuit in a product or a software update for
    * such product, must reproduce the above copyright notice, this list of
    * conditions and the following disclaimer in the documentation and/or other
    * materials provided with the distribution.
    *
    * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
    * contributors may be used to endorse or promote products derived from this
    * software without specific prior written permission.
    *
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • sdk_config.h is too big so I can't upload here. but, whole file is exactly same with the sdk_config.h of ble_app_uart_pca10056_s140 project. The SDK version is 15.3.0

  • Since the response syntax is <CR><LF><response><CR><LF>, then it might make sense to only print the response when you get a new-line character.

    How does the response look like if you change the uart_event_handle() to this?

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    void uart_event_handle(app_uart_evt_t * p_event)
    {
    static uint8_t data_array[BLE_NUS_MAX_DATA_LEN];
    static uint8_t index = 0;
    uint32_t err_code;
    switch (p_event->evt_type)
    {
    case APP_UART_DATA_READY:
    UNUSED_VARIABLE(app_uart_get(&data_array[index]));
    index++;
    if ((data_array[index - 1] == '\n') ||
    (index >= (m_ble_nus_max_data_len)))
    {
    if(index > 1)
    {
    // NRF_LOG_HEXDUMP_DEBUG(data_array, index);
    NRF_LOG_INFO("%s", data_array);
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX