<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Using chatgpt to write code for the nrf52840....]]></title><description><![CDATA[<p dir="auto">I haven't confirmed whether the offered solution will work or not, but it took only one second to generate, so on that basis alone I'm impressed.</p>
<p dir="auto">Anyone here using chatgpt for actual coding of any kind?</p>
<p dir="auto">By way of example, I gave this prompt:</p>
<pre><code>Without using zephyr, write a program for the nrf52840 to send a "Happy Birthday!" text message using the proprietary radio mode.
</code></pre>
<p dir="auto">and chatgpt's response was:</p>
<p dir="auto">To send a "Happy Birthday!" text message using the nRF52840 in proprietary radio mode without using the Zephyr RTOS, you can use Nordic Semiconductor's nRF5 SDK. Here's a basic example of how to create a custom radio communication program for the nRF52840. Please note that this code is a simplified example, and in a real-world scenario, you would implement error handling and more robust communication protocols.</p>
<p dir="auto"><strong>Transmitter (TX) Code:</strong></p>
<pre><code class="lang-c">#include &lt;stdint.h&gt;
#include &lt;stdbool.h&gt;
#include "nrf.h"
#include "nrf_gpio.h"

#define RADIO_CHANNEL 76  // Choose a custom channel

void radio_init(void) {
    NRF_RADIO-&gt;TXPOWER = RADIO_TXPOWER_TXPOWER_0dBm;
    NRF_RADIO-&gt;FREQUENCY = RADIO_CHANNEL;
    NRF_RADIO-&gt;MODE = RADIO_MODE_MODE_Nrf_2Mbit;
    NRF_RADIO-&gt;SHORTS = 0;
    NRF_RADIO-&gt;PCNF0 = (1 &lt;&lt; RADIO_PCNF0_LFLEN_Pos);
    NRF_RADIO-&gt;PCNF1 = (1 &lt;&lt; RADIO_PCNF1_WHITEEN_Pos) | (3 &lt;&lt; RADIO_PCNF1_BALEN_Pos);
    NRF_RADIO-&gt;BASE0 = 0xE7E7E7E7;
    NRF_RADIO-&gt;BASE1 = 0x43434343;
    NRF_RADIO-&gt;PREFIX0 = 0x55443322;
    NRF_RADIO-&gt;TXADDRESS = 0x00;
    NRF_RADIO-&gt;RXADDRESSES = 0x01;
}

void radio_send(const uint8_t *data, uint8_t length) {
    NRF_RADIO-&gt;PACKETPTR = (uint32_t)data;
    NRF_RADIO-&gt;EVENTS_READY = 0;
    NRF_RADIO-&gt;EVENTS_END = 0;

    NRF_RADIO-&gt;TASKS_TXEN = 1;
    while (NRF_RADIO-&gt;EVENTS_READY == 0);

    NRF_RADIO-&gt;TASKS_START = 1;

    while (NRF_RADIO-&gt;EVENTS_END == 0);
    NRF_RADIO-&gt;EVENTS_END = 0;

    NRF_RADIO-&gt;TASKS_DISABLE = 1;
    while (NRF_RADIO-&gt;EVENTS_DISABLED == 0);
}

int main(void) {
    nrf_gpio_cfg_output(20); // LED on pin 20

    radio_init();

    while (1) {
        // Message to send
        uint8_t message[] = "Happy Birthday!";
        uint8_t message_len = sizeof(message) - 1; // Exclude null-terminator

        // Send the message
        radio_send(message, message_len);

        // Toggle an LED to indicate a transmission
        nrf_gpio_pin_toggle(20);

        // Delay between transmissions
        for (int i = 0; i &lt; 1000000; i++) {
            __NOP();
        }
    }
}
</code></pre>
<p dir="auto"><strong>Receiver (RX) Code:</strong></p>
<pre><code class="lang-c">#include &lt;stdint.h&gt;
#include &lt;stdbool.h&gt;
#include "nrf.h"
#include "nrf_gpio.h"

#define RADIO_CHANNEL 76  // Should match the transmitter's channel

void radio_init(void) {
    NRF_RADIO-&gt;TXPOWER = RADIO_TXPOWER_TXPOWER_0dBm;
    NRF_RADIO-&gt;FREQUENCY = RADIO_CHANNEL;
    NRF_RADIO-&gt;MODE = RADIO_MODE_MODE_Nrf_2Mbit;
    NRF_RADIO-&gt;SHORTS = 0;
    NRF_RADIO-&gt;PCNF0 = (1 &lt;&lt; RADIO_PCNF0_LFLEN_Pos);
    NRF_RADIO-&gt;PCNF1 = (1 &lt;&lt; RADIO_PCNF1_WHITEEN_Pos) | (3 &lt;&lt; RADIO_PCNF1_BALEN_Pos);
    NRF_RADIO-&gt;BASE0 = 0xE7E7E7E7;
    NRF_RADIO-&gt;BASE1 = 0x43434343;
    NRF_RADIO-&gt;PREFIX0 = 0x55443322;
    NRF_RADIO-&gt;TXADDRESS = 0x00;
    NRF_RADIO-&gt;RXADDRESSES = 0x01;
}

void radio_receive(uint8_t *data, uint8_t *length) {
    NRF_RADIO-&gt;PACKETPTR = (uint32_t)data;
    NRF_RADIO-&gt;EVENTS_READY = 0;
    NRF_RADIO-&gt;EVENTS_END = 0;

    NRF_RADIO-&gt;TASKS_RXEN = 1;
    while (NRF_RADIO-&gt;EVENTS_READY == 0);

    NRF_RADIO-&gt;TASKS_START = 1;

    while (NRF_RADIO-&gt;EVENTS_END == 0);
    NRF_RADIO-&gt;EVENTS_END = 0;

    NRF_RADIO-&gt;TASKS_DISABLE = 1;
    while (NRF_RADIO-&gt;EVENTS_DISABLED == 0);

    *length = NRF_RADIO-&gt;RXMATCH;
}

int main(void) {
    nrf_gpio_cfg_output(20); // LED on pin 20

    radio_init();

    while (1) {
        uint8_t message[16]; // Adjust the buffer size as needed
        uint8_t message_len = 0;

        // Receive a message
        radio_receive(message, &amp;message_len);

        // Toggle an LED to indicate a reception
        nrf_gpio_pin_toggle(20);

        // Process the received message (e.g., print it)
        if (message_len &gt; 0) {
            message[message_len] = '\0'; // Null-terminate the received data
            printf("Received: %s\n", message);
        }
    }
}
</code></pre>
<p dir="auto">This code sets up a transmitter (TX) and receiver (RX) using the nRF52840's radio peripheral. The TX repeatedly sends the "Happy Birthday!" message, and the RX receives and prints any incoming messages. Make sure both devices are configured to use the same radio channel and have matching radio settings.</p>
<p dir="auto">Remember to adapt this code to your specific hardware setup and application requirements, and consider adding more robust error handling for a production-quality solution.</p>
]]></description><link>https://forum.mysensors.org/topic/12188/using-chatgpt-to-write-code-for-the-nrf52840</link><generator>RSS for Node</generator><lastBuildDate>Wed, 18 Nov 2026 18:22:52 GMT</lastBuildDate><atom:link href="https://forum.mysensors.org/topic/12188.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 14 Sep 2023 01:59:28 GMT</pubDate><ttl>60</ttl></channel></rss>