This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

A simple BLE-less UART example not working on nRF51822

I am trying to do a simple UART test with nRF51822 without BLE functionality. The code is a simplified version of the UART example in nRF51 SDK, and can be found here . It is really not much there: it sends the data from RX back to TX; if it gets a 'q' or 'Q', it just quits. I use an external serial monitor (Bus Pirate) to interact with it. However, two strange things happen:

  1. If I compile it without SoftDevice (and ROM address starts with 0x00000), I can see nothing from my serial monitor, no matter what I type in.

  2. If I compile it with SoftDevice 8.0.0 (although it doesn't use any BLE functions, and ROM address starts with 0x18000), I can repetitively see "Start:" and "Hit.", even I type in nothing in my serial monitor, and there is no 1000ms delay in the between. It is strange because a) "Start:" is not part of the while loop and should only be printed out once in the beginning; b) If "Hit." means the while loop is executed, there should be 1000 ms delay.

Can anyone advise what I am missing in such a simple UART program?

  • Hi Diode,

    1. If the same code starts with softdevice then it should work fine without it if you have set the IROM and IRAM addresses accordingly. With your example softdevice does nothing but jump correctly to you application. you can try to debug the code without softdevice to see if your main is being executed.

    2. May be your serial monitor is configured to have flow control and It is possible that you have typed something on serial emulator before starting your application which was in the emulator TX buffer waiting to be transmitted (as nothing on the other side is ready to receive). As soon as you flashed your board, your app received that char and moved out of waiting.

    also if you want to have 1000ms wait in between Start and Hit, you need to swap this lines

                            printf("Hit.\r\n");
                            nrf_delay_ms(1000);
    
  • Thanks for your reply. I reflashed the code without SoftDevice, and now at least it behaved similarly (and abnormally) as the one with SoftDevice. For your first comment, even if somehow my serial monitor was sending something to trigger the while loop, I shouldn't see "Start:" over and over in my serial monitor, since that string printf was outside the while loop. I tried the Jlink debugger and set breakpoints in "while(app_uart_get(&cr) != NRF_SUCCESS);" and " while(app_uart_put(cr) != NRF_SUCCESS);". I kept hitting F5 and could see the input characters I typed bounced back to my serial monitor (which was something I should expect). However, as long as I removed the second breakpoint, I couldn't see the same behavior. Also, every time I typed in "Return" key to the serial monitor in debugging session, I saw "Start:" which shouldn't there.

  • Regarding your second comment, my serial monitor was not configured to have flow control. And even if I have something left in TX buffer, it should be depleted after a few runs. But I kept seeing those characters. Those were so bizarre to me since it was such a simple application.

  • sorry, I missed to see that it is happening repetitively A Note though your Start cannot happen repetitively as this is outside the loop. Seems like a reset happening somewhere, I cannot understand where and why.

  • Hi Aryan. It turns out the it was because of the serial monitor was using open-drain mode so that it could not pull the line high. After switching it to normal mode (can pull the line high), I can see the loopback testing work on my serial command. Another small question: after hitting "q" the program will enter a infinite loop state. However, it gets itself out in a second or so and print out "Start:" (meaning a reset). Is this behavior expected because of something else (e.g. watchdog)?

Related