<?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>Software UART through emulated GPIO pins for nrf52833.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/116323/software-uart-through-emulated-gpio-pins-for-nrf52833</link><description>Hi there, 
 Currently, I&amp;#39;m working on a solution where I need to design a software UART through emulated GPIO pins for nrf52833. 
 The requirements are that, solution would be all in bare-metal, I mean, without using the SDK. 
 Then, if you could help</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 13 Nov 2024 03:11:49 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/116323/software-uart-through-emulated-gpio-pins-for-nrf52833" /><item><title>RE: Software UART through emulated GPIO pins for nrf52833.</title><link>https://devzone.nordicsemi.com/thread/510211?ContentTypeID=1</link><pubDate>Wed, 13 Nov 2024 03:11:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:02f2147b-185f-4c54-8eaf-703910d71258</guid><dc:creator>Felix Shih</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;ChatGPT gives the following reference code, and I don&amp;#39;t test it, maybe not work. Just for your reference.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#include &amp;quot;nrf_gpio.h&amp;quot;
#include &amp;quot;nrf_timer.h&amp;quot;
#include &amp;quot;nrf_drv_timer.h&amp;quot;

#define TX_PIN 17
#define RX_PIN 18

volatile uint8_t tx_buffer = 0;
volatile uint8_t rx_buffer = 0;
volatile bool tx_ready = true;
volatile bool rx_ready = false;

void timer_handler(void) {
    if (tx_ready) {
        nrf_gpio_pin_toggle(TX_PIN);
        tx_ready = false;
    }
    if (rx_ready) {
        rx_ready = false;
        rx_buffer = nrf_gpio_pin_read(RX_PIN);
    }
}

void uart_send(uint8_t byte) {
    tx_buffer = byte;
    tx_ready = true;
}

uint8_t uart_receive(void) {
    while (!rx_ready) {
        // Wait for data to be ready
    }
    return rx_buffer;
}

void setup(void) {
    nrf_gpio_cfg_output(TX_PIN);
    nrf_gpio_cfg_input(RX_PIN, NRF_GPIO_PIN_PULLUP);
    nrf_drv_timer_init(&amp;amp;timer, NRF_TIMER_MODE_COMPARE, false, timer_handler);
    nrf_drv_timer_start(&amp;amp;timer, NRF_TIMER_TICKS_PER_US, false);
}

int main(void) {
    setup();
    while (1) {
        uart_send(0x55); // Send a byte
        uint8_t received_byte = uart_receive(); // Receive a byte
    }
}
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>