<?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>TWIM0 not starting in custom driver</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/125278/twim0-not-starting-in-custom-driver</link><description>I am trying to write a low level driver for the TWIM system in a nrf52840 and cannot seem to get the hardware to transfer the TX data out of memory. For many reasons, I do not wish to use the provided libraries for this function although I did refer to</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 14 Nov 2025 23:27:58 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/125278/twim0-not-starting-in-custom-driver" /><item><title>RE: TWIM0 not starting in custom driver</title><link>https://devzone.nordicsemi.com/thread/554435?ContentTypeID=1</link><pubDate>Fri, 14 Nov 2025 23:27:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:effe84e7-0ec1-4eae-bba9-fa9a053157a2</guid><dc:creator>PaulJ</dc:creator><description>&lt;p&gt;OK, some humble pie for me....&lt;/p&gt;
&lt;p&gt;Firstly, I did a poor job of comparing my code to the bare metal code that Sigurd provided. My biggest error was not noticing that the &amp;quot;NRF_TWIM0-&amp;gt;ENABLED&amp;quot; is set to ON with a &amp;quot;6&amp;quot;, not a &amp;quot;1&amp;quot;. The second error(s) were the &amp;quot;SHORTS&amp;quot; and &amp;quot;EVENTS&amp;quot;. I clearly did not fully understand the logic of that system! So now I have a system that seems to be writing and reading to my peripheral. The numbers look goofy right now but I&amp;#39;m sure that&amp;#39;s a &amp;quot;ME&amp;quot; problem (again).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWIM0 not starting in custom driver</title><link>https://devzone.nordicsemi.com/thread/554321?ContentTypeID=1</link><pubDate>Fri, 14 Nov 2025 04:13:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bc367015-dafd-4dfb-a3a2-34ae13144d15</guid><dc:creator>PaulJ</dc:creator><description>&lt;p&gt;After much editing of various config files and finding a bad connection on my usb cable, I now am getting a &amp;quot;NACK&amp;quot; error recorded on the TWIM registers. Since this is a brand new PCB that I manually assembled, there is a good chance that the IC connected to the I2C bus is not soldered properly so I will try fixing that next and report back if it completely fixes the issue.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWIM0 not starting in custom driver</title><link>https://devzone.nordicsemi.com/thread/552939?ContentTypeID=1</link><pubDate>Thu, 30 Oct 2025 22:20:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cf9ddd1e-2a6d-4e7d-91cb-27e2be6ffc3c</guid><dc:creator>PaulJ</dc:creator><description>&lt;p&gt;A further update: I did see that they recommend that you explicitly clear certain registers in the peripherals that share the same base address as TWIM0. I double checked, and none of the conflicting registers are enabled, have any PPI, or have any interrupts set.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWIM0 not starting in custom driver</title><link>https://devzone.nordicsemi.com/thread/552937?ContentTypeID=1</link><pubDate>Thu, 30 Oct 2025 20:20:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4068ff1c-54d5-4598-91fd-c2204f9f151f</guid><dc:creator>PaulJ</dc:creator><description>&lt;p&gt;I added the two external pullups (4K) and retested. Still no success in starting the TWIM. I looked at the pin states after I configured the GPIO and they are both showing as &amp;quot;INPUT&amp;quot; and &amp;quot;HIGH&amp;quot;. However, as soon as I execute:&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;NRF_TWIM0&lt;/span&gt;&lt;span&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;ENABLE&lt;/span&gt;&lt;span&gt; = &lt;/span&gt;&lt;span&gt;1&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;both pins states go low! It seems to me that the TWIM system should maintain these as &amp;quot;HIGH&amp;quot; when no data is being transferred. Is that any sort of clue as to what is set up incorrectly?&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWIM0 not starting in custom driver</title><link>https://devzone.nordicsemi.com/thread/552926?ContentTypeID=1</link><pubDate>Thu, 30 Oct 2025 16:11:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4d431753-4829-4f07-9235-26bd0b4347b9</guid><dc:creator>PaulJ</dc:creator><description>&lt;p&gt;I thought that I could use the internal pullup resistors for the TWI system so I did not include pullups on my custom PCB. I can see now that the &amp;quot;pullup&amp;quot; is only for the &amp;quot;input&amp;quot; configuration. Would the lack of external pullups prevent the TWM from setting its flags as I described above? I will add them now (somehow) and report back but added this interim comment in case people are searching for a similar issue.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWIM0 not starting in custom driver</title><link>https://devzone.nordicsemi.com/thread/552805?ContentTypeID=1</link><pubDate>Wed, 29 Oct 2025 16:12:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e740417b-cc69-4a62-8828-99ed329d0d9e</guid><dc:creator>PaulJ</dc:creator><description>&lt;p&gt;Thanks for providing the Nordic bare metal version of the TWIM code. I went through it all and really the only difference between my version and yours is that the &amp;quot;SHORT&amp;quot; is set each time for the read or write whereas I was configuring both SHORTS in my init function. Obviously the physical pins used, the device address, and buffers are different in my version so I used the values suitable to my hardware. Also, your code sets it up for 400KHz while I was trying for 100Khz (at least initially anyway).&lt;/p&gt;
&lt;p&gt;I&amp;#39;m afraid the results are the same; the control registers for the TWIM all appear to be set properly (ENABLE = 1, MAXCNT = non zero, DATA_PTR set to RAM location, PSEL = my pin numbers, FREQ = 400khz, DEV_ADDR = my device address. When I execute &amp;quot;NRF_TWIM0-&amp;gt;TASKS_STARTTX = 1;&amp;quot;, absolutely nothing changes in the system registers so the end condition &amp;quot;while (NRF_TWIM0-&amp;gt;EVENTS_STOPPED == 0);&amp;quot; never exits.&lt;/p&gt;
&lt;p&gt;Are there any other hardware systems in the nrf52840 that might interfere with this module? Could there be an issue by using the single step in debug mode?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWIM0 not starting in custom driver</title><link>https://devzone.nordicsemi.com/thread/552768?ContentTypeID=1</link><pubDate>Wed, 29 Oct 2025 13:40:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:380e339b-903c-49de-ab13-3b28d65ce9c5</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Hi!&lt;/p&gt;
&lt;p&gt;I strongly recommend using the provided libraries and drivers&lt;/p&gt;
&lt;p&gt;That said, if you want to try something very bare-metal, try something like this:&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;#include &amp;lt;nrf.h&amp;gt;

#define DEVICE_ADDRESS (0x34)
#define PIN_SCL        (27)
#define PIN_SDA        (26)

void i2c_write(uint8_t addr, uint8_t data)
{
  uint8_t tx_buf[2];
  NRF_TWIM0-&amp;gt;SHORTS = TWIM_SHORTS_LASTTX_STOP_Msk;

  tx_buf[0] = addr;
  tx_buf[1] = data;
  NRF_TWIM0-&amp;gt;TXD.MAXCNT = sizeof(tx_buf);
  NRF_TWIM0-&amp;gt;TXD.PTR = (uint32_t)&amp;amp;tx_buf[0];

  NRF_TWIM0-&amp;gt;EVENTS_STOPPED = 0;
  NRF_TWIM0-&amp;gt;TASKS_STARTTX = 1;
  while (NRF_TWIM0-&amp;gt;EVENTS_STOPPED == 0);
}

uint8_t i2c_read(uint8_t addr)
{
  uint8_t tx_buf[1];
  uint8_t rx_buf[1];
  NRF_TWIM0-&amp;gt;SHORTS = TWIM_SHORTS_LASTTX_STARTRX_Msk | TWIM_SHORTS_LASTRX_STOP_Msk;

  tx_buf[0] = addr;
  NRF_TWIM0-&amp;gt;TXD.MAXCNT = sizeof(tx_buf);
  NRF_TWIM0-&amp;gt;TXD.PTR = (uint32_t)&amp;amp;tx_buf[0];

  NRF_TWIM0-&amp;gt;RXD.MAXCNT = 1;
  NRF_TWIM0-&amp;gt;RXD.PTR = (uint32_t)&amp;amp;rx_buf[0];

  NRF_TWIM0-&amp;gt;EVENTS_STOPPED = 0;
  NRF_TWIM0-&amp;gt;TASKS_STARTTX = 1;
  while (NRF_TWIM0-&amp;gt;EVENTS_STOPPED == 0);

  return rx_buf[0];
}

int main(void)
{
  volatile uint8_t data;

  NRF_TWIM0-&amp;gt;PSEL.SCL = PIN_SCL;
  NRF_TWIM0-&amp;gt;PSEL.SDA = PIN_SDA;

  NRF_TWIM0-&amp;gt;ADDRESS = DEVICE_ADDRESS;
  NRF_TWIM0-&amp;gt;FREQUENCY = TWIM_FREQUENCY_FREQUENCY_K400 &amp;lt;&amp;lt; TWIM_FREQUENCY_FREQUENCY_Pos;
  NRF_TWIM0-&amp;gt;SHORTS = 0;

  NRF_TWIM0-&amp;gt;ENABLE = TWIM_ENABLE_ENABLE_Enabled &amp;lt;&amp;lt; TWIM_ENABLE_ENABLE_Pos;

  i2c_write(0x0, 0xFF);

  data = i2c_read(0x0);
  data; // to get rid of set but unused warning

  while (1)
  {
    __WFE();
  }
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>