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

Problem communicating via UART in non-blocking mode with higher baud rates

Hi,

I am trying to communicate with a Wi-Fi module external to nRF52840 via UART. I am using the nrf_serial_read() API. I have tried different values for UART baud rate from 115200 to 921600 but nothing works in the non-blocking mode(timeout_ms = 0).

The only working combinations between 115200 and 921600 are:
Baud rate                   Timeout         

115200                      125ms
230400                      100ms

Q1) Is the timeout necessary to make the UART communication work with a high baud rate?

Q2) I need to achieve a baud rate of 921600 for a smoother application with a minimum timeout in ms. Is there a way to achieve it? 

Thanks,
Akhil

Parents Reply
  • Hi

    I got the nrf_serial_read working. I see that the communication is successful but I get framing errors and cannot receive complete data even with 115200 baud rate at timeout = 0.
    Same is the case with all other baud rates till 921600. 

    But, for baud rate 115200, I see reliable communication without any framing error for timeout = 125ms. 

    I guess you're right, the timeout shouldn't matter but the timeout is playing some role here and I am confused about that.

Children
  • Hi,

    What kind of WiFi module is this?

    Do you have a logic analyzer or an oscilloscope so we can see what goes on on the TX and RX lines?

  • I am using Zentri AMW007, a stand-alone Wi-Fi networking module. 

    I do have an oscilloscope with me. Yes, I'll try scoping the TX, RX.

  • Hi Martin, 
    We have scoped the TX and RX and are able to see good signal flow over the lines. 

    What do you think could be a possible reason causing this problem? Any thoughts? 

  • It sounds strange. 

    1. This is a two way communication right?
    2. How do you set the baud rate used by the AMW007? Are you sure that both devices use the same baud rate?
    3. Do you have a link to some datasheet detailing how you configure the baud rate on the AMW007?
    4. Maybe the AMW007 is slow to respond and that is why you need a timeout? 
    5. Can  you show me more of the code you use to read and write data?
  • 1. Yes, It is a 2 way communication. It's called command mode on Zentri with an open com port, I send 
        commands from nRF52840 and receive response from the Zentri AMW007.
    2. There are a set of commands associated with Zentri OS that I can send to set the baud rate and also
        read it back. Here's the link to the resource: 
    3. docs.zentri.com/.../uart
    4. I have an Zentri Eval board with AMW007. I have tested it by connecting it to a PC and sending the       
        same commands with all available baud rates. It works perfectly fine without any timeout.
        Also, The communication doesn't work if the baud rate is not same. I receive no response at the
        Nordic end and which is very much expected for UART communication. 

        NOTE: For baud rate 921600, I do not receive complete data even if the timeout is anywhere
                    between 2000 ms and 5000 ms.

    5.  I have a diagnostics Shell running for user(CLI) and the code flow is like this: 
         I receive a command from the CLI and forward that command to Zentri module using       
         nrf_serial_write()       API and similarly read the data on the bus(response from Zentri) using
         nrf_serial_read() API.

         Here're the code snippet for TX the command to Zentri and RX the response: 

    ret_code_t wlan_serial_tx(void const * p_data, size_t size)
    {
        ret_code_t ret;

        ret = nrf_serial_write(&wlan_serial_uart,
             p_data, size, NULL, 500);

       return ret;
    }


    ret_code_t wlan_serial_read(void * p_data, size_t size, size_t* bytes_read, uint32_t ms_wait)
    {
        ret_code_t ret;

        if (ms_wait)
       {
             ret = nrf_serial_read(&wlan_serial_uart, p_data, size, bytes_read, ms_wait);
       } else {
              ret = nrf_serial_read(&wlan_serial_uart, p_data, size, bytes_read, 1000);
       }
    return ret;
     }

       void wlan_send_to_zentri(char* command)
     {
        ret_code_t ret;
       char full_response[ZENTRI_UART_MAX_BYTES] = {0};
       size_t strsize, bytes_read;
       strsize = strlen(command);

       ret = wlan_serial_tx(command, strsize);
       APP_ERROR_CHECK(ret);

      /* Try to read everything */
      wlan_serial_read(full_response, ZENTRI_UART_MAX_BYTES, &bytes_read, uart_ms_timeout);

      printf("\n%s", full_response);

      /* Flush out the UART */
      while(bytes_read)
      {
         wlan_serial_read(full_response, ZENTRI_UART_MAX_BYTES, &bytes_read);
         if (bytes_read)
        {
           printf("%s", full_response);
        }
      }
     }



    Thanks,
    Akhil


Related