nRF52840 UART send more than 256 bytes

I'm sending some data from nRF52840 to another device through wired UART. When data is less than 256-byte long, it works fine. But when it's larger than 256 bytes, I get ERROR 4 [NRF_ERROR_NO_MEM]. I have already changed UART_TX_BUF_SIZE to 1024 in APP_UART_FIFO_INIT. Is there anything else I should change? Thanks

Parents
  • Hello, 

    It should be sufficient to only increase the FIFO TX buffer. Are you able to debug the app to see exactly where the NRF_ERROR_NO_MEM is returned? Is it from the app_fifo_put() call in app_uart_put()? 

    Thanks,

    Vidar

  • Hello,

    The printout from RTT viewer just shows NRF_ERROR_NO_MEM at the line of app_uart_put(). How do I get deep into app_uart_put()?

    Thanks

  • Just tried changing 1024 to 2048, it's still the same error. 

    Do you have access to private case 314336? I posted the complete code there to ask for another question. 

  • Yes, I can access the ticket. Are you logging the UART output from the device when the error arises? I see that you are sending UART data from multiple places in your code and it would be helpful to know how much data has been sent before the error occurs. The issue is likely that data is being added to the FIFO buffer faster than it's being transmitted over UART. 

    Also, where did you increase the packet length to 257 bytes?

  • This happens at line 753. This is the only place calling uart_send function at that time. 

    Data is set from line 719 to 722. Total array length is 270, I just play with uint16_t data_length = 16. When data_length is set to 16, the total data to send is 257 and it reports error. If I change data_length to 14, total data length is 255 and it works. 

  • How much data has been sent up to that point, and how often is this function being called? Your 1024-byte FIFO obviously shouldn't return NRF_ERROR_NO_MEM if you're only sending a single 257-byte packet.

  • I send scan results through UART, so a lot up to this point. This function is only called once a peripheral is connected. 

    But I really doubt it has anything to do with potential data left in the buffer, because 255 is guaranteed to work, 257 is guaranteed to have error no matter how long I have been scanning and sending scan results. 

Reply
  • I send scan results through UART, so a lot up to this point. This function is only called once a peripheral is connected. 

    But I really doubt it has anything to do with potential data left in the buffer, because 255 is guaranteed to work, 257 is guaranteed to have error no matter how long I have been scanning and sending scan results. 

Children
  • It might be a good idea to check if you can send more than 257 bytes at the beginning of the main function before you begin scanning for BT devices.

    E.g.,

    Fullscreen
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • I added the following code to main before the loop

    Fullscreen
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    It works fine when data_length is 255.

    Getting NRF_ERROR_NO_MEM when data_length is 256.

  • Why don't you try to send the data right after "uart_init" as shown in my code snippet before you start scanning, etc.? I've not been able to reproduce the error here with the NUS example.

  • This is before scanning and anything else using UART. 

  • I see the problem now. In your uart_send() implementation you have a for loop that looks like this:

    Fullscreen
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    where the loop control variable 'i' is an uint8_t which will overflow after reaching '256'.