<?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 problems on the nRF9160 DK (bare metal programming)</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/93996/uart-problems-on-the-nrf9160-dk-bare-metal-programming</link><description>I am trying to get the UARTE0 on the nRF9160 DK to transmit some bytes through the Virtual COM port. I am not sure why it does not work. I have included my source code below. I have done some debugging with an oscilloscope on the TXD pin (P0.29) and the</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 21 Nov 2022 21:35:30 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/93996/uart-problems-on-the-nrf9160-dk-bare-metal-programming" /><item><title>RE: UART problems on the nRF9160 DK (bare metal programming)</title><link>https://devzone.nordicsemi.com/thread/396767?ContentTypeID=1</link><pubDate>Mon, 21 Nov 2022 21:35:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0f7d7be6-0972-48f5-bb45-5c8b95c77de3</guid><dc:creator>PVH</dc:creator><description>&lt;p&gt;Thanks a lot for the very useful information, H&amp;aring;kon &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: UART problems on the nRF9160 DK (bare metal programming)</title><link>https://devzone.nordicsemi.com/thread/396749?ContentTypeID=1</link><pubDate>Mon, 21 Nov 2022 18:06:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c3946b2e-c771-46a6-9332-ac9b2063208c</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;Glad to hear its working on your side as well!&lt;/p&gt;
[quote userid="112475" url="~/f/nordic-q-a/93996/uart-problems-on-the-nrf9160-dk-bare-metal-programming/396738"]1. I did not have to use the PIN_CNF registers. But, I guess it might give more control over the GPIOs, although the registers are marked as &amp;quot;retained&amp;quot; in the datasheet?[/quote]
&lt;p&gt;It isn&amp;#39;t strictly needed, as the hardware peripheral itself will claim the pins.&lt;/p&gt;
&lt;p&gt;in cases where you need to disable the uart (for sleep purposes, lowers the current), you&amp;#39;d want to set the pin itself as idle, ie. high for serial communication. Then it is usually good to ensure that this is already set in the GPIO registers when the UARTE peripheral releases said pins.&lt;/p&gt;
[quote userid="112475" url="~/f/nordic-q-a/93996/uart-problems-on-the-nrf9160-dk-bare-metal-programming/396738"]Well, this is embarrassing - I just assumed it was enabled by a &amp;quot;1&amp;quot; :-)[/quote]
&lt;p&gt;Don&amp;#39;t worry, I have done the same mistake many times.&lt;/p&gt;
[quote userid="112475" url="~/f/nordic-q-a/93996/uart-problems-on-the-nrf9160-dk-bare-metal-programming/396738"]I guess this is how the device knows if the peripheral should be enabled as UART, SPI, TWI, etc.?[/quote]
&lt;p&gt;Very good catch! Yes, this sets the&amp;nbsp;hardware peripheral in &amp;quot;the wanted serial mode&amp;quot; state.&lt;/p&gt;
&lt;p&gt;&amp;#39;8&amp;#39; for UARTE, &amp;#39;9&amp;#39; for TWIS etc.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;H&amp;aring;kon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: UART problems on the nRF9160 DK (bare metal programming)</title><link>https://devzone.nordicsemi.com/thread/396738?ContentTypeID=1</link><pubDate>Mon, 21 Nov 2022 16:26:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6cbf5f2e-53f1-41d5-80b3-d80ec7d50f1f</guid><dc:creator>PVH</dc:creator><description>&lt;p&gt;Thank you very much, H&amp;aring;kon - it works now :-)&lt;/p&gt;
&lt;p&gt;1. I did not have to use the PIN_CNF registers. But, I guess it might give more control over the GPIOs, although the registers are marked as &amp;quot;retained&amp;quot; in the datasheet?&lt;/p&gt;
&lt;p&gt;2. Yes... I forgot. Thank you for pointing that out.&lt;/p&gt;
&lt;p&gt;3. Well, this is embarrassing - I just assumed it was enabled by a &amp;quot;1&amp;quot; :-) I guess this is how the device knows if the peripheral should be enabled as UART, SPI, TWI, etc.?&lt;/p&gt;
&lt;p&gt;I have included my working code below and a scope screenshot:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#include &amp;quot;nrfx.h&amp;quot;

int main()
{
    // Use the HFXO as the high frequency clock
    NRF_CLOCK-&amp;gt;TASKS_HFCLKSTART = 1;
    while (! NRF_CLOCK-&amp;gt;EVENTS_HFCLKSTARTED); // Wait for the clock to start
    NRF_CLOCK-&amp;gt;EVENTS_HFCLKSTARTED = 0;

    // The primary virtual COM port on nRF9160 DK is using the following pins:
    // P0.26 CTS, P0.27 RTS, P0.28 RXD and P0.29 TXD
    
    // Configure the GPIOs
    NRF_P0-&amp;gt;DIRCLR = (1&amp;lt;&amp;lt;28) | (1&amp;lt;&amp;lt;26); // Set RXD and CTS pins as inputs
    NRF_P0-&amp;gt;DIRSET = (1&amp;lt;&amp;lt;29) | (1&amp;lt;&amp;lt;27); // Set TXD and RTS pins as outputs
    NRF_P0-&amp;gt;OUTSET = (1&amp;lt;&amp;lt;29) | (1&amp;lt;&amp;lt;29); // Set TXD and RTS pins high
    
    // Route the UARTE0 pins to the above GPIOs
    NRF_UARTE0-&amp;gt;PSEL.CTS = 26;
    NRF_UARTE0-&amp;gt;PSEL.RTS = 27;
    NRF_UARTE0-&amp;gt;PSEL.RXD = 28;
    NRF_UARTE0-&amp;gt;PSEL.TXD = 29;
    
    // Configure the UART with no hardware flow control, no parity bit, one
    // stop bit and a baud rate of 115200.
    NRF_UARTE0-&amp;gt;CONFIG = 0;
    NRF_UARTE0-&amp;gt;BAUDRATE = 0x01D60000ul;

    // Enable the UART
    NRF_UARTE0-&amp;gt;ENABLE = UARTE_ENABLE_ENABLE_Enabled &amp;lt;&amp;lt; UARTE_ENABLE_ENABLE_Pos;
        
    // Set up the UART to transmit these bytes
    static uint8_t data[] = { 0xDE, 0xAD, 0xBE, 0xEF };
    NRF_UARTE0-&amp;gt;TXD.MAXCNT = 4;
    NRF_UARTE0-&amp;gt;TXD.PTR = (uint32_t)data;
    
    // Main loop that repeatedly transmits the above data
    while (1)
    {
        NRF_UARTE0-&amp;gt;TASKS_STARTTX = 1;      // Start the transmission
        while (! NRF_UARTE0-&amp;gt;EVENTS_ENDTX); // Wait for transmission to finish
        NRF_UARTE0-&amp;gt;EVENTS_ENDTX = 0;       // Clear the ENDTX event
    }
    
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&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/nRF9160_2D00_uart_2D00_test.png" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: UART problems on the nRF9160 DK (bare metal programming)</title><link>https://devzone.nordicsemi.com/thread/396403?ContentTypeID=1</link><pubDate>Fri, 18 Nov 2022 12:37:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:792da3b4-8fbf-46d0-9dbe-5eff2cc22e64</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;I would recommend that you use defines in the nrf9160_bitfields.h&amp;nbsp;for writing/reading registers.&lt;/p&gt;
&lt;p&gt;I got it working on my side, but there&amp;#39;s 3 things needed to be done:&lt;/p&gt;
&lt;p&gt;1. Configure your pins as input/output in the NRF_P0-&amp;gt;PIN_CNF[] registers.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;	NRF_P0-&amp;gt;PIN_CNF[26] |= GPIO_PIN_CNF_DIR_Input &amp;lt;&amp;lt; GPIO_PIN_CNF_DIR_Pos;
	NRF_P0-&amp;gt;PIN_CNF[27] |= GPIO_PIN_CNF_DIR_Output &amp;lt;&amp;lt; GPIO_PIN_CNF_DIR_Pos;
	NRF_P0-&amp;gt;PIN_CNF[28] |= GPIO_PIN_CNF_DIR_Input &amp;lt;&amp;lt; GPIO_PIN_CNF_DIR_Pos;
	NRF_P0-&amp;gt;PIN_CNF[29] |= GPIO_PIN_CNF_DIR_Output &amp;lt;&amp;lt; GPIO_PIN_CNF_DIR_Pos;
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;2. EasyDMA cannot read from flash. Change the &amp;quot;data&amp;quot; array to a static uint8_t, ie. not a const.&lt;/p&gt;
&lt;p&gt;3. The .ENABLE register value for UARTE is &amp;#39;8&amp;#39;.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;    // Enable the UART
    NRF_UARTE0-&amp;gt;ENABLE = UARTE_ENABLE_ENABLE_Enabled &amp;lt;&amp;lt; UARTE_ENABLE_ENABLE_Pos;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Could you try this and see if it works?&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></channel></rss>