<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>how to send uart data over ble with nrf52840 dongle</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/73629/how-to-send-uart-data-over-ble-with-nrf52840-dongle</link><description>I&amp;#39;m working on pca10059(nRF52840 dongle) to send UART data over bluetooth to another device. 
 My test environment is, 
 Arduino Uno to send uart signal using &amp;quot;mySerial.write(&amp;quot;Hello World\n&amp;quot;);&amp;quot;, 
 pca10059 device that I&amp;#39;m trying to develop to send uart</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 09 Apr 2021 12:40:40 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/73629/how-to-send-uart-data-over-ble-with-nrf52840-dongle" /><item><title>RE: how to send uart data over ble with nrf52840 dongle</title><link>https://devzone.nordicsemi.com/thread/304011?ContentTypeID=1</link><pubDate>Fri, 09 Apr 2021 12:40:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:53eb9a0f-6768-42e2-a89c-e50a7a38f4ce</guid><dc:creator>Senchoi</dc:creator><description>&lt;p&gt;Although I felt very lucky to get these replies.&lt;/p&gt;
&lt;p&gt;I think I&amp;#39;ve found out why uart_event_handle didn&amp;#39;t send the data.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;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-&amp;gt;evt_type)
    {
        case APP_UART_DATA_READY:
            UNUSED_VARIABLE(app_uart_get(&amp;amp;data_array[index]));
            index++;

            if ((data_array[index - 1] == &amp;#39;\n&amp;#39;) ||
                (data_array[index - 1] == &amp;#39;\r&amp;#39;) ||
                (index &amp;gt;= m_ble_nus_max_data_len))
            {
                if (index &amp;gt; 1)
                {
                    NRF_LOG_DEBUG(&amp;quot;Ready to send data over BLE NUS&amp;quot;);
                    NRF_LOG_HEXDUMP_DEBUG(data_array, index);

                    do
                    {
                        uint16_t length = (uint16_t)index;
                        err_code = ble_nus_data_send(&amp;amp;m_nus, data_array, &amp;amp;length, m_conn_handle);
                        printf(&amp;quot;%s\r\n&amp;quot;, data_array);
                        if ((err_code != NRF_ERROR_INVALID_STATE) &amp;amp;&amp;amp;
                            (err_code != NRF_ERROR_RESOURCES) &amp;amp;&amp;amp;
                            (err_code != NRF_ERROR_NOT_FOUND))
                        {
                            APP_ERROR_CHECK(err_code);
                        }
                    } while (err_code == NRF_ERROR_RESOURCES);
                }

                index = 0;
            }
            break;

        case APP_UART_COMMUNICATION_ERROR:
            APP_ERROR_HANDLER(p_event-&amp;gt;data.error_communication);
            break;

        case APP_UART_FIFO_ERROR:
            APP_ERROR_HANDLER(p_event-&amp;gt;data.error_code);
            break;

        default:
            break;
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The function above has certain condition for sending data over ble.&lt;/p&gt;
&lt;p&gt;if ((data_array[index - 1] == &amp;#39;\n&amp;#39;) ||&lt;br /&gt; (data_array[index - 1] == &amp;#39;\r&amp;#39;) ||&lt;br /&gt; (index &amp;gt;= m_ble_nus_max_data_len))&lt;/p&gt;
&lt;p&gt;this seems the part that I should&amp;#39;ve understood. When sending the data from Arduino I had to send &amp;#39;\n&amp;#39; at the end.&lt;/p&gt;
&lt;p&gt;It seems above handler waits for the condition above.&lt;/p&gt;
&lt;p&gt;This is the Arduino code that works now.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#include &amp;lt;SoftwareSerial.h&amp;gt;

SoftwareSerial mySerial(2, 3); // RX, TX

void setup()
{
  // Open serial communications and wait for port to open:
  Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Native USB only
  }


  Serial.println(&amp;quot;Goodnight moon!&amp;quot;);

  // set the data rate for the SoftwareSerial port
  mySerial.begin(115200);
  mySerial.println(&amp;quot;Hello, world?&amp;quot;);
}
char c = &amp;#39;a&amp;#39;;
void loop() // run over and over
{
  
  if (mySerial.available()){
    Serial.write(mySerial.read());
    if (c == &amp;#39;z&amp;#39; + 1)
      c = &amp;#39;a&amp;#39;;
    mySerial.write(c++);mySerial.write(&amp;#39;\n&amp;#39;);
  }
  delay(500);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I can see the sent data from python shell with the setup I had.&lt;/p&gt;
&lt;p&gt;I have tones of other questions but I guess I can wrap it up for now.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to send uart data over ble with nrf52840 dongle</title><link>https://devzone.nordicsemi.com/thread/303968?ContentTypeID=1</link><pubDate>Fri, 09 Apr 2021 10:58:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ceff72ec-8925-42e0-9068-675f1c15fde1</guid><dc:creator>Karl Ylvisaker</dc:creator><description>[quote user="Senchoi"]&lt;p&gt;I did not fully understand this part but as I tried app_uart_put it sends to arduino just fine.&lt;/p&gt;
&lt;p&gt;I&amp;#39;m a bit confused because the issue at this moment is arduino not sending uart signal to NRF. I&amp;#39;m not sure why arduino&amp;#39;s RX register matters.&lt;/p&gt;[/quote]
&lt;p&gt;Thats great to hear - so now we know that the issue is with the arduino sending over uart, not with the NRF and its RX/TX. This is great to know for the continued debugging effort.&lt;br /&gt;The reason I asked you to do this test was to figure out if the issue was with the nrf or the arduino.&lt;br /&gt;It was not clear to me that the issue was on the arduino&amp;#39;s side prior to you confirming this.&lt;/p&gt;
[quote user="Senchoi"]I guess this issue is not going to end unless I can fully understand what&amp;#39;s going on in UART. Would it help to get logic analyzer?[/quote]
&lt;p&gt;There are always ways to get around it, but they are tedious and take a lot longer. Being enable to see exactly what is happening on the lines help tremendously when working with all serial protocols, since it is the only way to know what is&amp;nbsp;&lt;em&gt;actually&amp;nbsp;&lt;/em&gt;happening.&amp;nbsp;&lt;/p&gt;
[quote user="Senchoi"]But modifying existing handler to send the received data back to arduino is a little out of my capability. I was kinda hoping to know a sure way to receive uart data from arduino since the error code is 5.[/quote]
&lt;p&gt;I am sure you will be able to modify this if you had wanted - but since we now know that the issue is on the arduino side you do not have to make this modification, since we are past that part of the debugging. If the arduino is not sending correctly, there is nothing you can do on the nrf side to alleviate this, so we will have to look at the arduino side to resolve this.&lt;/p&gt;
[quote user="Senchoi"]if&amp;nbsp;&lt;span&gt;uart_event_handle function is supposed to handle incoming uart data just fine and arduino is the only problem, figuring out what&amp;#39;s exactly happening might be a waste of time because final product wouldn&amp;#39;t work with arduino.&lt;/span&gt;[/quote][quote user="Senchoi"]is&amp;nbsp;uart_event_handle function implemented and getting it used in uart_init enough to make it deliver the data just fine?[/quote]
&lt;p&gt;Yes, you are right. The default uart_event_handler in the ble_app_uart example does exactly this - whenever it receives something through UART it queues it for sending over BLE.&lt;br /&gt;I was not aware that you do not intend to keep the arduino in your project. I suppose you could say that debugging the arduino is then a waste of time, but then again - what did you hope to achieve with the arduino in the first place? Certainly these goals will not be met if you abandon the arduino now.&lt;/p&gt;
[quote user="Senchoi"]if this works I might not even have to use logic analyzer.[/quote]
&lt;p&gt;In the short term this looks to be the case then, yes. For future development it would however be&amp;nbsp;&lt;em&gt;very useful&lt;/em&gt; for you to have access to a logic analyzer when developing with serial protocols.&lt;br /&gt;Fortunately, logic analyzers are quite easy to come by these days, and there exists many cheap versions out there, so at least it might be something to look into, for you own future sake.&lt;/p&gt;
[quote user="Senchoi"]After commenting out uart_init function. It seems the test I was doing works fine. The one with sending 111. Only if printf function would work without breaking texts.[/quote]
&lt;p&gt;I am not sure what you mean by this. Are you saying that if you comment out uart_init, you are able to pass the byte with value 111 back and forth as expected?&lt;br /&gt;As I mentioned earlier, the retargeted printf actually uses the app_uart_put function behind the curtains. You could check the retargeting library source code to see this for yourself. This means that if you use printf, it is the same as calling app_uart_put on a cstring containing whatever you tried to have print.&lt;br /&gt;If you refrain for using the retargeted printf function, this should not be an issue.&lt;/p&gt;
[quote user="Senchoi"]shouldn&amp;#39;t retval be NRF_SUCCESS when it gets data from RX?[/quote]
&lt;p&gt;Yes, it should be NRF_SUCCESS if it has successfully retrieved a byte from the UART RX buffer.&lt;br /&gt;This is the kind of issue we could easily avoid if we had a logic analyzer scope the communication, because suddenly it seems like the arduino is sending the data as expected.&lt;br /&gt;&lt;br /&gt;On a general note the returned error code should usually be passed to an APP_ERROR_CHECK for handling, but this is not necessary in this simple debugging test program. I just thought I should mention it for future development.&lt;/p&gt;
[quote user="Senchoi"]But the code below this prints out on arduino just like it&amp;#39;s expected.[/quote]
&lt;p&gt;Are you saying that you are then able to pass the same &amp;#39;111&amp;#39; valued byte back and forth?&lt;/p&gt;
[quote user="Senchoi"]With the code below, nothing prints out on arduino.[/quote]
&lt;p&gt;On a general note you should always use braces around your conditional statements, it is considered bad practice for maintainability to leave the braces out just because you technically can. &lt;a href="https://stackoverflow.com/questions/2125066/is-it-a-bad-practice-to-use-an-if-statement-without-curly-braces"&gt;Please see this StackOverflow answer for more detail&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to send uart data over ble with nrf52840 dongle</title><link>https://devzone.nordicsemi.com/thread/303876?ContentTypeID=1</link><pubDate>Thu, 08 Apr 2021 22:21:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9efbb086-65dc-45da-a50c-49f680ee1378</guid><dc:creator>Senchoi</dc:creator><description>&lt;p&gt;This is also interesting.&lt;/p&gt;
&lt;p&gt;With the code below, nothing prints out on arduino.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;    uint8_t data;
    uint32_t retval;
    for (;;)
    {
        retval=app_uart_get(&amp;amp;data);
        if(retval==NRF_SUCCESS)
          app_uart_put(data);
        nrf_delay_ms(500);
    }&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;But the code below this prints out on arduino just like it&amp;#39;s expected.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;    uint8_t data;
    uint32_t retval;
    for (;;)
    {
        retval=app_uart_get(&amp;amp;data);
        app_uart_put(data);
        nrf_delay_ms(500);
    }&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;shouldn&amp;#39;t retval be NRF_SUCCESS when it gets data from RX?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to send uart data over ble with nrf52840 dongle</title><link>https://devzone.nordicsemi.com/thread/303863?ContentTypeID=1</link><pubDate>Thu, 08 Apr 2021 18:16:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e65ebc1c-e9cc-42c1-8861-1780475e7798</guid><dc:creator>Senchoi</dc:creator><description>&lt;p&gt;After commenting out uart_init function. It seems the test I was doing works fine. The one with sending 111. Only if printf function would work without breaking texts.&lt;/p&gt;
&lt;p&gt;Still If I could not use uart_event_handle function I don&amp;#39;t know how to send this uart data, 111 in this case, over bluetooth.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to send uart data over ble with nrf52840 dongle</title><link>https://devzone.nordicsemi.com/thread/303846?ContentTypeID=1</link><pubDate>Thu, 08 Apr 2021 15:52:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a47d4360-14fa-432d-bd79-64288a70fed9</guid><dc:creator>Senchoi</dc:creator><description>&lt;p&gt;Another thing,&lt;/p&gt;
&lt;p&gt;if&amp;nbsp;&lt;span&gt;uart_event_handle function is supposed to handle incoming uart data just fine and arduino is the only problem, figuring out what&amp;#39;s exactly happening might be a waste of time because final product wouldn&amp;#39;t work with arduino.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;What I could do is testing it with the actual final setup that&amp;#39;s going to be in place of current arduino.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;is&amp;nbsp;uart_event_handle function implemented and getting it used in uart_init enough to make it deliver the data just fine?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;if this works I might not even have to use logic analyzer.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to send uart data over ble with nrf52840 dongle</title><link>https://devzone.nordicsemi.com/thread/303840?ContentTypeID=1</link><pubDate>Thu, 08 Apr 2021 15:28:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1bd35aa0-05c2-46c0-acd6-9ef439f0f4f0</guid><dc:creator>Senchoi</dc:creator><description>&lt;p&gt;And is there anything else that&amp;#39;s helpful other than logic analyzer?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to send uart data over ble with nrf52840 dongle</title><link>https://devzone.nordicsemi.com/thread/303837?ContentTypeID=1</link><pubDate>Thu, 08 Apr 2021 15:23:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5f9ef81c-f5f4-43ac-b813-c8e1a2528d38</guid><dc:creator>Senchoi</dc:creator><description>[quote userid="87869" url="~/f/nordic-q-a/73629/how-to-send-uart-data-over-ble-with-nrf52840-dongle/303790#303790"]On the Arduino side, have the arduino send a single known byte periodically, for example a byte with value 111. Have the arduino check if it has received anything in its UART RX register by checking .available() with following .read() periodically, and if it has have the arduino toggle a LED or something similar - the arduino should also check the value of the byte it has received, to see if it matches the value of the byte it sent.[/quote]
&lt;p&gt;I did not fully understand this part but as I tried app_uart_put it sends to arduino just fine.&lt;/p&gt;
&lt;p&gt;I&amp;#39;m a bit confused because the issue at this moment is arduino not sending uart signal to NRF. I&amp;#39;m not sure why arduino&amp;#39;s RX register matters.&lt;/p&gt;
&lt;p&gt;My goal is eventually to deliver series of uint8_t data periodically over ble.&lt;/p&gt;
&lt;p&gt;I can understand the importance of sending periodical data from arduino and let dongle&amp;#39;s handler handle the data. But modifying existing handler to send the received data back to arduino is a little out of my capability. I was kinda hoping to know a sure way to receive uart data from arduino since the error code is 5.&lt;/p&gt;
&lt;p&gt;I guess this issue is not going to end unless I can fully understand what&amp;#39;s going on in UART. Would it help to get logic analyzer?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to send uart data over ble with nrf52840 dongle</title><link>https://devzone.nordicsemi.com/thread/303790?ContentTypeID=1</link><pubDate>Thu, 08 Apr 2021 13:17:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cc441913-0d6e-4676-94a0-0c8b2b7c27e5</guid><dc:creator>Karl Ylvisaker</dc:creator><description>[quote user="Senchoi"]&lt;p&gt;Also i&amp;#39;m not sure If it&amp;#39;s because of connection. &amp;quot;0 received. 5 is the retval.&amp;quot; message breaks like crazy.&lt;/p&gt;
&lt;p&gt;something like..&lt;/p&gt;[/quote]
&lt;p&gt;The returned value of app_uart_get is an uint32_t, not an int, I am not sure that the arduino decodes it correctly in the printf statement.&lt;br /&gt;&lt;a href="https://stackoverflow.com/questions/14911813/what-is-the-difference-between-an-uint32-and-an-unsigned-int-in-c#:~:text=1%20Answer&amp;amp;text=uint32_t%20(or%20however%20pre%2DC,0%2D65535%20minimum%20range)."&gt;Take a look at this stackoverflow answer&lt;/a&gt; for a more indepth explanation of why it is important to be exact with these types.&lt;/p&gt;
[quote user="Senchoi"]I don&amp;#39;t understand. Should I ask this in arduino community about how to send uart signal other than mySerial.write function?[/quote]
&lt;p&gt;Keep in mind that the app_uart_get function retrieves&amp;nbsp;&lt;em&gt;one byte&amp;nbsp;&lt;/em&gt;at the time.&lt;br /&gt;Reading the .write arduino documentation again seems to say that the .write takes an array, or a single value. In this case, a byte with value 111 should have been written.&lt;br /&gt;&lt;br /&gt;However, you are also first attempting to write what you have received last, with the .write(&lt;a href="https://www.arduino.cc/en/Reference/SoftwareSerialRead"&gt;.read()&lt;/a&gt;) function. Then we need to look at what your arduino might be receiving over the UART. In this case, it looks like it will receive the cstring from your printf statement.&lt;br /&gt;This is certainly a little chaotic.&lt;br /&gt;&lt;br /&gt;I am not certain that the logic in your test is correct. Please write down what you tried to have happen in this code. If the goal was to periodically send a byte with value 111 that is not what you are currently doing.&lt;br /&gt;&lt;br /&gt;How about this instead:&lt;br /&gt;On the NRF side, implement the test as part of the uart RX event handler, have it retrieve the one byte using app_uart_get, and then send the same byte back by using &lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fsdk_nrf5_v17.0.2%2Fgroup__app__uart.html&amp;amp;cp=7_1_6_10_57_14&amp;amp;anchor=ga2e4c8407274a151e72ed5a226529dc36"&gt;app_uart_put&lt;/a&gt;&amp;nbsp;for only that single byte, received over UART. &lt;em&gt;Do not use printf for anything &lt;/em&gt;in this test, as the retargeting of printf will have its output be put on the UART, creating clutter.&lt;br /&gt;Let your main() loop only contain the idle_state_handler call.&lt;br /&gt;&lt;br /&gt;On the Arduino side, have the arduino send a single known byte periodically, for example a byte with value 111. Have the arduino check if it has received anything in its UART RX register by checking .available() with following .read() periodically, and if it has have the arduino toggle a LED or something similar - the arduino should also check the value of the byte it has received, to see if it matches the value of the byte it sent.&lt;br /&gt;&lt;br /&gt;Implement this test, and see if it results in the LED toggling every 500 ms period on the arduino, then you will know that their communication is working as it should.&lt;br /&gt;&lt;br /&gt;I think part of the issue here is that you have not checked your returned error codes, and that you have mixed up what is actually happening on the UART interface, since you are using printf on both sides in combination with your test byte. Additionally I think the test logic on the arduino side might not have achieved exactly what you hoped to.&lt;br /&gt;&lt;br /&gt;This is where a logical analyzer would make the work a lot easier, since we immediately would see what is going on on the UART - but we will find a way to make due without the analyzer.&lt;br /&gt;&lt;br /&gt;Looking forward to resolving this issue together!&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to send uart data over ble with nrf52840 dongle</title><link>https://devzone.nordicsemi.com/thread/303765?ContentTypeID=1</link><pubDate>Thu, 08 Apr 2021 12:21:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ab45f970-ef29-49af-a604-0f2366bdd27e</guid><dc:creator>Senchoi</dc:creator><description>&lt;p&gt;The error code is five which must be NRF_ERROR_NOT_FOUND.&lt;/p&gt;
&lt;p&gt;I guess arduino is not sending the uart signal for some reason.&lt;/p&gt;
&lt;p&gt;Here&amp;#39;s my arduino code...&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#include &amp;lt;SoftwareSerial.h&amp;gt;

SoftwareSerial mySerial(2, 3); // RX, TX

void setup()
{
  // Open serial communications and wait for port to open:
  Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Native USB only
  }


  Serial.println(&amp;quot;Goodnight moon!&amp;quot;);

  // set the data rate for the SoftwareSerial port
  mySerial.begin(115200);
  mySerial.println(&amp;quot;Hello, world?&amp;quot;);
}

void loop() // run over and over
{
  if (mySerial.available()){
    Serial.write(mySerial.read());
    mySerial.write(111);
  }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Here&amp;#39;s my dongle code in the main function.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;    uint8_t data;
    int retval;
    for (;;)
    {
        retval = app_uart_get(&amp;amp;data);
        printf(&amp;quot;%u received. %d is the retval.\n&amp;quot;, data, retval);
        //idle_state_handle();
        //nrf_pwr_mgmt_run();
        //NRF_LOG_FLUSH();
        nrf_delay_ms(500);
    }&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;this setup constantly prints out &amp;quot;0 received. 5 is the retval.&amp;quot; in every 500ms.&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t understand. Should I ask this in arduino community about how to send uart signal other than mySerial.write function?&lt;/p&gt;
&lt;p&gt;Also i&amp;#39;m not sure If it&amp;#39;s because of connection. &amp;quot;0 received. 5 is the retval.&amp;quot; message breaks like crazy.&lt;/p&gt;
&lt;p&gt;something like..&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;0 recived.  is th retal.
0 recdved. 5 s theretal.
0 rece⸮⸮⸮s&#x2;⸮~⸮.A⸮⸮⸮⸮g⸮[I⸮0 receved.5 Z.ݫ⸮⸮х⸮⸮
0 reaeiv;⸮. 5 iq⸮&#xF;⸮&#x16;W&amp;amp;⸮va[⸮⸮0 received. 5 isthe reval.
0 recewed. 5 is he reval.
0 rY⸮YZY⸮	&#x13;J́⸮⸮⸮⸮⸮х⸮⸮R0 received. 5 is th re:val.
0 receve⸮. 5 is the 9eval.&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to send uart data over ble with nrf52840 dongle</title><link>https://devzone.nordicsemi.com/thread/303729?ContentTypeID=1</link><pubDate>Thu, 08 Apr 2021 11:09:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8c7bb74a-472e-4564-a63a-7020967fbd39</guid><dc:creator>Karl Ylvisaker</dc:creator><description>[quote user="Senchoi"]That&amp;#39;s just how &amp;quot;the other&amp;quot; dongle is programmed. &amp;quot;the other&amp;quot; dongle listens ble signal and sends Serial signal to the computer. When python reads the other dongle and there&amp;#39;s no data, it prints out 0 after timeout period that is set in Python code. It will print something other than 0 before timeout when &amp;quot;the other&amp;quot; dongle reads something.[/quote]
&lt;p&gt;Aha, I misinterpreted your &amp;#39;s&amp;#39; as a shorthand for seconds, instead of plural, thank you for clarifying.&lt;/p&gt;
[quote user="Senchoi"]testing part in the dongle is below code in the main function out of loop.[/quote]
&lt;p&gt;You are not checking the &lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fsdk_nrf5_v17.0.2%2Fgroup__app__uart.html&amp;amp;anchor=gacddb5b7b711ef104f9eb181a13bc4503"&gt;returned error code of app_uart_get&lt;/a&gt;. You should&amp;nbsp;&lt;em&gt;always&lt;/em&gt; check the returned error code - if you do not, you have no way of knowing whether the function succeeded or not.&amp;nbsp;&lt;/p&gt;
[quote user="Senchoi"]Arduino code looks like this[/quote]
&lt;p&gt;I am not too familiar with arduino code personally, but it looks to me like your conditional statements check whether to write something only if it has already received something?&lt;br /&gt;Your conditionals use the&amp;nbsp;&lt;a href="https://www.arduino.cc/en/Reference/SoftwareSerialAvailable"&gt;.available()&lt;/a&gt;&amp;nbsp;function, which only will evaluate to true if data has already been received over UART. It looks to me like none of those lines will ever run, unless the dongle starts out by sending something over UART to the arduino.&lt;br /&gt;Could you also have you arduino either toggle a LED or give some other indication that it is writing to UART? You could for example base this on the returned value from the &lt;a href="https://www.arduino.cc/en/Reference/SoftwareSerialWrite"&gt;.write()&lt;/a&gt; function.&amp;nbsp;&lt;/p&gt;
[quote user="Senchoi"]But it seems idle_state_handle() in the for loop constantly turns the dongle on and off for power management since &amp;quot;0 received&amp;quot; prints out about every half a second when the dongle is connected to Arduino.[/quote]
&lt;p&gt;The idle_state_handler checks whether there are logs that needs processing, and if not it places the CPU in a low power SYSTEM_ON state (idle) to save power. It does not turn off the dongle (SYSTEM_OFF). Since you are not checking the error code returned by the app_uart_get function the function might never actually succeed, and this might be why you are seeing the repeated 0 (if this is the initialized value of the data variable).&lt;br /&gt;You could check this by either checking the returned error code -&lt;em&gt; which you always should do&amp;nbsp;&lt;/em&gt;-, or by initializing the data variable to a known other value, and seeing if this is the value you are seeing repeatedly.&lt;br /&gt;&lt;br /&gt;Looking forward to resolving this issue together!&lt;br /&gt;&lt;br /&gt;Best regards,&amp;nbsp;&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to send uart data over ble with nrf52840 dongle</title><link>https://devzone.nordicsemi.com/thread/303708?ContentTypeID=1</link><pubDate>Thu, 08 Apr 2021 10:30:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:796a63c3-4a61-419d-8c09-3fec563a1164</guid><dc:creator>Senchoi</dc:creator><description>&lt;p&gt;There&amp;#39;s a typo in the code in this part.&lt;/p&gt;
[quote userid="103143" url="~/f/nordic-q-a/73629/how-to-send-uart-data-over-ble-with-nrf52840-dongle/303707#303707"]testing part in the dongle is below code[/quote]
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;uint8_t data;
app_uart_get(&amp;amp;data);
printf(&amp;quot;%u received&amp;quot;, data);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I left out &amp;quot;f&amp;quot; from printf function. My apologies.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to send uart data over ble with nrf52840 dongle</title><link>https://devzone.nordicsemi.com/thread/303707?ContentTypeID=1</link><pubDate>Thu, 08 Apr 2021 10:27:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c1d44121-21cb-4e87-88b0-d9698d32be78</guid><dc:creator>Senchoi</dc:creator><description>[quote userid="87869" url="~/f/nordic-q-a/73629/how-to-send-uart-data-over-ble-with-nrf52840-dongle/303704#303704"]I don&amp;#39;t fully understand what you mean by this sentence. The python code is made to print something on the serial terminal after a timeout of 0s...? Please elaborate on this.[/quote]
&lt;p&gt;That&amp;#39;s just how &amp;quot;the other&amp;quot; dongle is programmed. &amp;quot;the other&amp;quot; dongle listens ble signal and sends Serial signal to the computer. When python reads the other dongle and there&amp;#39;s no data, it prints out 0 after timeout period that is set in Python code. It will print something other than 0 before timeout when &amp;quot;the other&amp;quot; dongle reads something.&lt;/p&gt;
[quote userid="87869" url="~/f/nordic-q-a/73629/how-to-send-uart-data-over-ble-with-nrf52840-dongle/303704#303704"]This is an interesting find that indicates that that the UART data is not processed correctly.&lt;br /&gt;Could you show me the specific code you used for this test?[/quote]
&lt;p&gt;Arduino code looks like this&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#include &amp;lt;SoftwareSerial.h&amp;gt;

SoftwareSerial mySerial(2, 3); // RX, TX

void setup()
{
  // Open serial communications and wait for port to open:
  Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Native USB only
  }


  Serial.println(&amp;quot;Goodnight moon!&amp;quot;);

  // set the data rate for the SoftwareSerial port
  mySerial.begin(115200);
  mySerial.println(&amp;quot;Hello, world?&amp;quot;);
}

void loop() // run over and over
{
  if (mySerial.available())
    Serial.write(mySerial.read());
  if (Serial.available())
    mySerial.write(111);
  //delay(500);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;testing part in the dongle is below code in the main function out of loop.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;uint8_t data;
app_uart_get(&amp;amp;data);
print(&amp;quot;%u received&amp;quot;, data);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;But it seems idle_state_handle() in the for loop constantly turns the dongle on and off for power management since &amp;quot;0 received&amp;quot; prints out about every half a second when the dongle is connected to Arduino.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to send uart data over ble with nrf52840 dongle</title><link>https://devzone.nordicsemi.com/thread/303704?ContentTypeID=1</link><pubDate>Thu, 08 Apr 2021 09:56:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f7f1fbc2-269d-4514-95a5-e10b7f45ba5c</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello,&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
[quote user="Senchoi"]Thank you for your reply,[/quote]
&lt;p&gt;No problem at all, I am happy to help!&lt;br /&gt;&lt;br /&gt;Thank you for elaborating - this is very helpful for me to understand your project and issue better.&lt;/p&gt;
[quote user="Senchoi"]Arduino ide&amp;#39;s serial monitor prints out dongle&amp;#39;s &amp;quot;printf(&amp;quot;\r\nUART started.\r\n&amp;quot;);&amp;quot; part repetitively once in every half a second. Although the loop doesn&amp;#39;t have any delay and there&amp;#39;s no setup of half a second in dongle program(main.c file below).[/quote]
&lt;p&gt;This might be caused by a non-NRF_SUCCESS error code being passed to an APP_ERROR_CHECK.&lt;br /&gt;Since you only have 1 UART hardware interface, and you are using it in your application, it makes us unable to get the debug information from the logger directly.&lt;br /&gt;So instead, we will have to implement something more than the default error-handling, to root out what this issue is.&lt;br /&gt;Alternatively, you could take a look at &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/65716/rtt-logging-interferes-with-usb/268608#268608"&gt;Jimmy&amp;#39;s comment in this ticket&lt;/a&gt;&amp;nbsp;where he describes how to get the logger information output over USB - this would be very useful to have during development.&lt;/p&gt;
[quote user="Senchoi"]When I check Python IDLE the python code prints out data after set timeout which is 0s instead of &amp;quot;hello world&amp;quot;.[/quote]
&lt;p&gt;I don&amp;#39;t fully understand what you mean by this sentence. The python code is made to print something on the serial terminal after a timeout of 0s...? Please elaborate on this.&lt;/p&gt;
[quote user="Senchoi"]I haven&amp;#39;t found such indication. Unfortunately all I have is two dongles and this arduino kit.[/quote]
&lt;p&gt;It is all right, then we will have to make due with these, no problem.&lt;/p&gt;
[quote user="Senchoi"]When I used app_uart_get function to receive numbers and sent it right back it just printed out 0. I had sent 111 on the other hand.[/quote]
&lt;p&gt;This is an interesting find that indicates that that the UART data is not processed correctly.&lt;br /&gt;Could you show me the specific code you used for this test?&lt;br /&gt;&lt;br /&gt;On a general note I notice that you have&amp;nbsp;&lt;em&gt;a lot&lt;/em&gt; of commented out code in your project source code.&lt;br /&gt;I strongly recommend that you move these out of your working document, since this greatly reduced readability and clutters up your IDE. If you have code that you think might be useful later, I suggest moving it to another document for storage, rather than keeping it commented out in the source code.&lt;br /&gt;&lt;br /&gt;Looking forward to resolving this issue together!&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to send uart data over ble with nrf52840 dongle</title><link>https://devzone.nordicsemi.com/thread/303602?ContentTypeID=1</link><pubDate>Wed, 07 Apr 2021 19:13:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e1a0312d-2014-4d10-b5e6-7100f50ca286</guid><dc:creator>Senchoi</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/0451.main.c"&gt;devzone.nordicsemi.com/.../0451.main.c&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Thank you for your reply,&lt;/p&gt;
&lt;p&gt;History of this project is pretty long. I don&amp;#39;t think I could give you all the details but I&amp;#39;ll do my best.&lt;/p&gt;
&lt;p&gt;Base of (1) is ble_app_uart/pca10056/s140....emproject file.&lt;/p&gt;
[quote userid="87869" url="~/f/nordic-q-a/73629/how-to-send-uart-data-over-ble-with-nrf52840-dongle/303547#303547"]Did you make any other changes to its functionality?[/quote]
&lt;p&gt;They first transplanted SAADC functions to make it work for something. But I disabled this part in the main function eventually because it&amp;#39;s no longer needed&lt;/p&gt;
&lt;p&gt;And my mate added send_triangular_wave function to it and this sends&amp;nbsp;&lt;span&gt;uint8_t&amp;nbsp;signal over bluetooth so that I could check with Python IDLE&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Also, he changed&amp;nbsp;MIN_CONN_INTERVAL to be 50ms instead of 20ms.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Change I made was, in uart_init function these four parts to suit the wiring,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;.rx_pin_no = 29,&lt;br /&gt; .tx_pin_no = 31,&lt;br /&gt; .rts_pin_no = UART_PIN_DISCONNECTED,&lt;br /&gt; .cts_pin_no = UART_PIN_DISCONNECTED,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
[quote userid="87869" url="~/f/nordic-q-a/73629/how-to-send-uart-data-over-ble-with-nrf52840-dongle/303547#303547"]what did you observe when it did not work?[/quote]
&lt;p&gt;&lt;span&gt;Arduino ide&amp;#39;s serial monitor prints out dongle&amp;#39;s &amp;quot;printf(&amp;quot;\r\nUART started.\r\n&amp;quot;);&amp;quot; part repetitively once in every half a second. Although the loop doesn&amp;#39;t have any delay and there&amp;#39;s no setup of half a second in dongle program(main.c file below).&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/0451.main.c"&gt;devzone.nordicsemi.com/.../0451.main.c&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;When I check Python IDLE the python code prints out data after set timeout which is 0s instead of &amp;quot;hello world&amp;quot;.&lt;/span&gt;&lt;/p&gt;
[quote userid="87869" url="~/f/nordic-q-a/73629/how-to-send-uart-data-over-ble-with-nrf52840-dongle/303547#303547"]a schematic would be very helpful to see[/quote]
&lt;p&gt;&lt;span&gt;&lt;/span&gt;I find it a little difficult to draw everything and the setup is not so complicated so I&amp;#39;ll use words.&lt;/p&gt;
&lt;p&gt;Arduino GND connected to dongle GND&lt;/p&gt;
&lt;p&gt;Arduino 3.3v connected to dongle VDD OUT&lt;/p&gt;
&lt;p&gt;Arduino digital pin 2(RX) &lt;span&gt;connected&amp;nbsp;&lt;/span&gt;to dongle 0.31&lt;/p&gt;
&lt;p&gt;Arduino digital pin 3(TX) &lt;span&gt;connected&amp;nbsp;&lt;/span&gt;to dongle 0.29&lt;/p&gt;
[quote userid="87869" url="~/f/nordic-q-a/73629/how-to-send-uart-data-over-ble-with-nrf52840-dongle/303547#303547"]Do you receive any indication from your dongle that an UART message has been received? The best way to check this is to have it connected to a logical analyzer, but if you do not have access to one you could also for testing purposes have the dongle loop back the received message. I.e if it receives a UART tranmission, it should send it back again immediately before continuing with its application execution.[/quote]
&lt;p&gt;I haven&amp;#39;t found such indication. Unfortunately all I have is two dongles and this arduino kit.&lt;/p&gt;
&lt;p&gt;When I used app_uart_get function to receive numbers and sent it right back it just printed out 0. I had sent 111 on the other hand.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to send uart data over ble with nrf52840 dongle</title><link>https://devzone.nordicsemi.com/thread/303547?ContentTypeID=1</link><pubDate>Wed, 07 Apr 2021 13:52:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:918af992-30e8-4cef-9ee1-52c83856af22</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello,&amp;nbsp;&lt;/p&gt;
[quote user=""](1) I&amp;#39;ve modified the project in example/ble_peripheral/ble_app_uart to send arbitrary data(series of&amp;nbsp;uint8_t signal) to another dongle and I could see the data in Python IDLE.[/quote]
&lt;p&gt;The ble_app_uart example already sends arbitrary (received over UART) uint8_t data to the connected device. Do you mean that you modified it to work with the nRF52840 Dongle (PCA10059)? Did you make any other changes to its functionality?&lt;/p&gt;
[quote user=""]I&amp;#39;ve changed the code (1) a little bit to see if I could send uart to the other dongle. It didn&amp;#39;t work.[/quote]
&lt;p&gt;How did you change the code, what functionality were you looking to implement, and what did you observe when it did not work?&lt;/p&gt;
[quote user=""]Most of what I&amp;#39;ve done is changing the TX RX pin number to suit wiring setup.[/quote]
&lt;p&gt;It would be great if you could be explicit here. What changes did you make, and how is your test setup currently wired (a schematic would be very helpful to see)?&lt;/p&gt;
[quote user=""]What&amp;#39;s hard to understand is the project already has uart_event_handle function in the main.c and it uses ble_nus_data_send function just like (1) but it seems it&amp;#39;s not responding to uart signal sent from arduino or it&amp;#39;s not sending the received uart signal.[/quote][quote user=""]Although I couldn&amp;#39;t check arduino&amp;#39;s uart signal, I&amp;#39;m quite sure (2) project&amp;#39;s success in test indicates it&amp;#39;s not a problem of connection or arduino code. Correct me if I&amp;#39;m wrong.[/quote]
&lt;p&gt;Do you receive any indication from your dongle that an UART message has been received? The best way to check this is to have it connected to a logical analyzer, but if you do not have access to one you could also for testing purposes have the dongle loop back the received message. I.e if it receives a UART tranmission, it should send it back again immediately before continuing with its application execution.&lt;br /&gt;It is always scary to assume that a certain operation or codeblock has executed successfully, without actually knowing.&lt;br /&gt;Could you share this part of the code with me, possibly?&lt;br /&gt;&lt;br /&gt;On a general note I would highly recommend acquiring and using the nRF52840 Development Kit for development, rather than the dongles. The dongle is a great companion to the DK during development, but a DK is much easier to work with and debug - especially so because of the on-board debugger.&lt;br /&gt;When working with the dongle it is recommended to have a look through &lt;a href="https://devzone.nordicsemi.com/nordic/short-range-guides/b/getting-started/posts/nrf52840-dongle-programming-tutorial"&gt;the Dongle Programming Tutorial&lt;/a&gt;&amp;nbsp;- but since you have already achieved the code modification and functionality in your (1) description, I suppose you know many of these things already.&lt;/p&gt;
&lt;p&gt;Looking forward to resolving this issue together!&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>