<?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>UART is not working consistently</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/99091/uart-is-not-working-consistently</link><description>Hey, 
 
 I am in the process of testing the UART peripheral. Currently we are developing an application for which we need the nrf9160 and the nrf52840 chipset . We have decided to use UART communication between the two chips. However, after testing the</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 14 Jun 2023 11:09:57 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/99091/uart-is-not-working-consistently" /><item><title>RE: UART is not working consistently</title><link>https://devzone.nordicsemi.com/thread/430974?ContentTypeID=1</link><pubDate>Wed, 14 Jun 2023 11:09:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:797ae5fa-9a29-4879-b260-70a7281e418b</guid><dc:creator>J0sh1101</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Sorry for the late reply. I update the RECEIVE_TIMEOUT to 10 ms. After initializing the buffer, the first few message there is some strange combination of characters, but after that it works as expected. I tried it couple of times I can reproduce it always.I will leave it as this as I have a lot of other things to do.&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:214px;max-width:214px;" height="214" src="https://devzone.nordicsemi.com/resized-image/__size/428x428/__key/communityserver-discussions-components-files/4/pastedimage1686740967147v1.png" width="214" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks for the help. Wish you a nice day!&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;ice day.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: UART is not working consistently</title><link>https://devzone.nordicsemi.com/thread/429495?ContentTypeID=1</link><pubDate>Tue, 06 Jun 2023 09:08:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:74ba7489-69cc-4520-9945-1e5c9a7dcfb5</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Could you try relaxing the define&amp;nbsp;RECEIVE_TIMEOUT? Please note that this input is in microseconds, not milliseconds.&lt;/p&gt;
&lt;p&gt;Try to set it a bit higher, as the uart transmission itself takes&amp;nbsp;approx. 8.7 us per bit transmitted.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: UART is not working consistently</title><link>https://devzone.nordicsemi.com/thread/429377?ContentTypeID=1</link><pubDate>Mon, 05 Jun 2023 15:12:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e4be898e-0555-43d5-a36a-3cfbce82b65b</guid><dc:creator>J0sh1101</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Sorry for the late replay.&lt;/p&gt;
&lt;p&gt;I am sending 26 bytes/characters. I have updated my project where I show the length of the message and also the buffer can be updated with a button. If the message fits completely in the buffer then I have no side effects. If the buffer is slightly different size then the callback function gets some weird data. Below you can see a snapshot of nrf5240:&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1685977189423v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I also tested it on the nrf9160 and it also had the same side effect:&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1685977662967v2.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;Here is the project:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/UART_5F00_test_5F00_2.zip"&gt;devzone.nordicsemi.com/.../UART_5F00_test_5F00_2.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;What could be the issue here? I also tested it with Putty and I am getting the same results.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks for the help.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: UART is not working consistently</title><link>https://devzone.nordicsemi.com/thread/423313?ContentTypeID=1</link><pubDate>Tue, 02 May 2023 13:17:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d4ce6b02-c600-49ac-bda5-5f52de79255c</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Are you certain that you&amp;#39;re receiving 25 bytes each time?&lt;/p&gt;
&lt;p&gt;You are not checking the received length (evt-&amp;gt;data.rx.len)&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: UART is not working consistently</title><link>https://devzone.nordicsemi.com/thread/423135?ContentTypeID=1</link><pubDate>Mon, 01 May 2023 16:01:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:baa828c4-e5b6-4c03-9d61-b2f45fbbf78b</guid><dc:creator>J0sh1101</dc:creator><description>[quote userid="2115" url="~/f/nordic-q-a/99091/uart-is-not-working-consistently/422572"]ur nrf9160dk_nrf9160_ns.overlay seems to switch TX and RX wrt. what is routed on the nRF9160-DK itself. TX=P0.01 and RX=P0.00 on the VCOM2 interface.[/quote]
&lt;p&gt;At the beginning I connect the RX of the nrf52840-DK to the TX of the nrf9160-DK and vice versa to make a roundtrip for a UART message to test it. I found that both UARTs behave the same strange behaviour as explained above. Afterwards, I used only one DK and connected the RX and TX together. I simplified my tests (the more devices involved, the more potential errors can occur).&lt;/p&gt;
[quote userid="2115" url="~/f/nordic-q-a/99091/uart-is-not-working-consistently/422572"]2. You should add a pull-resistor to the button. As it is active low, a pull-up is recommended:[/quote]
&lt;p&gt;Yes, you are right, and that is a good point to have in the code. Luckily, I have not experienced any sporadic button interrupts.I was more concetrated on the UART communication then on the button handling configuration. I will update the code. Thanks!&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
[quote userid="2115" url="~/f/nordic-q-a/99091/uart-is-not-working-consistently/422572"]&lt;p&gt;PS: Ideally, you want interrupt functions to be short, with no blocking functions.&lt;/p&gt;
&lt;p&gt;A button handler is effectively a interrupt handler, and calling a function with no timeout can cause issues further down the development path.&lt;/p&gt;[/quote]
&lt;p&gt;In production code I probably wouldn&amp;#39;t call a function in an interrupt handler, as you said this introduces a lot of problems (overhead of nested interrutps, code smells like tight-coupling)&lt;/p&gt;
&lt;p&gt;But for the quick and dirty prototyping approach that I will never use again afterwards, I will become a sinner.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
[quote userid="2115" url="~/f/nordic-q-a/99091/uart-is-not-working-consistently/422572"]Is the issue only present in the &amp;quot;Serial terminal&amp;quot; or do you see similar issues with for instance realterm/putty/teraterm?[/quote]
&lt;p&gt;After some additional testing and playing around, I found out that the RX buffer is a ring buffer. This is probably the best approach to avoid buffer problems.&lt;/p&gt;
&lt;p&gt;However, I sometimes get extra zeros in the temp buffer, which can cause the log function to display only an empty message. (I copy the data from the RX buffer with the offset into the temp buffer, but still get zeros in it).&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;img style="max-height:240px;max-width:320px;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1682955070312v1.png" /&gt;&lt;/p&gt;
&lt;p&gt;In between the buffer elements I get some strange values, for example on the 10th element, like &amp;#39;(&amp;#39;. This is something I don&amp;#39;t quite understand. I checked if there is something wrong with the wires. The logic analyzer can read the signal clearly and it looks really good, like in the picture above. I don&amp;#39;t think it&amp;#39;s a hardware problem. Here is how I connected the nrf52840-DK (pretty simple):&lt;/p&gt;
&lt;p style="padding-left:90px;"&gt;&lt;img style="max-height:240px;max-width:320px;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/photo1682956200.jpeg" /&gt;&lt;/p&gt;
&lt;p&gt;Is it possible to reset the write head of the ring buffer with the nrf function? When I read the message, I want the UART to write at the first element of the buffer and not where it ended at the last message.&lt;/p&gt;
&lt;p&gt;What would cause these strange values in the buffer?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: UART is not working consistently</title><link>https://devzone.nordicsemi.com/thread/422572?ContentTypeID=1</link><pubDate>Wed, 26 Apr 2023 14:41:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4fa6e792-5d11-437d-aab2-a8de8477bc82</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;1. your nrf9160dk_nrf9160_ns.overlay seems to switch TX and RX wrt. what is routed on the nRF9160-DK itself. TX=P0.01 and RX=P0.00 on the VCOM2 interface.&lt;/p&gt;
&lt;p&gt;2. You should add a pull-resistor to the button. As it is active low, a pull-up is recommended:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;ret = gpio_pin_configure_dt(&amp;amp;button, GPIO_INPUT | GPIO_PULL_UP);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Is the issue only present in the &amp;quot;Serial terminal&amp;quot; or do you see similar issues with for instance realterm/putty/teraterm?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;PS: Ideally, you want interrupt functions to be short, with no blocking functions.&lt;/p&gt;
&lt;p&gt;A button handler is effectively a interrupt handler, and calling a function with no timeout can cause issues further down the development path.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>