<?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>i2c/twi detup on register level</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/17867/i2c-twi-detup-on-register-level</link><description>Hello I&amp;#39;m trying to setup i2c/twi communication between nrf52832 with oled driver SH1107 but i need to do it in hardware instead of software but on the register level. 
 void initI2c()
{
	NRF_TWIM0-&amp;gt;SHORTS = 0x00001780;
	NRF_TWIM0-&amp;gt;INTEN = 0x019C0022;</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 25 Jan 2017 09:42:55 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/17867/i2c-twi-detup-on-register-level" /><item><title>RE: i2c/twi detup on register level</title><link>https://devzone.nordicsemi.com/thread/68880?ContentTypeID=1</link><pubDate>Wed, 25 Jan 2017 09:42:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9a990c0d-9079-485d-b52a-ca5c86c6e073</guid><dc:creator>luke</dc:creator><description>&lt;p&gt;thank u so much for ur help!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: i2c/twi detup on register level</title><link>https://devzone.nordicsemi.com/thread/68879?ContentTypeID=1</link><pubDate>Wed, 23 Nov 2016 14:00:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8b08d2f9-62f2-4246-9457-e00e529efc57</guid><dc:creator>Stian R&amp;#248;ed Hafskjold</dc:creator><description>&lt;p&gt;This line,&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;NRF_TWIM0-&amp;gt;SHORTS = 0x00001780;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;enables all shorts. Enable only one of them, like LASTTX_STOP. Which sets the stop signal after last byte has been transferred.&lt;/p&gt;
&lt;p&gt;Here you enable interrupt on all events:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;NRF_TWIM0-&amp;gt;INTEN = 0x019C0022;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Enable only the ones you need. In your example above, you don&amp;#39;t use interrupts at all, so you should set this register to 0.&lt;/p&gt;
&lt;p&gt;This line,&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;NRF_TWIM0-&amp;gt;ERRORSRC = 0x00000006;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;is only used for checking the error source when an error is encountered. Do not write to this register.&lt;/p&gt;
&lt;p&gt;You must write 1 to TASKS_STARTTX like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;NRF_TWIM0-&amp;gt;TASKS_STARTTX = 1;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;MyArrayList must be static so that the pointer is valid after the function returns. Something like this should work:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#define BUFFER_SIZE 2
#define TWI_SCL 13
#define TWI_SDA 14
typedef struct ArrayList
{
    uint8_t buffer[BUFFER_SIZE];
} ArrayList_type;

static ArrayList_type tx_buf[2];
static ArrayList_type * tx_buf_p = tx_buf;

void initI2c()
{
    NRF_GPIO-&amp;gt;PIN_CNF[TWI_SCL] = (6 &amp;lt;&amp;lt; 8) | (3 &amp;lt;&amp;lt; 2); //configure pins with pullup
    NRF_GPIO-&amp;gt;PIN_CNF[TWI_SDA] = (6 &amp;lt;&amp;lt; 8) | (3 &amp;lt;&amp;lt; 2);
    NRF_TWIM0-&amp;gt;SHORTS = (1 &amp;lt;&amp;lt; 9);     //LASTTX_STOP
    NRF_TWIM0-&amp;gt;PSEL.SCL = TWI_SCL;
    NRF_TWIM0-&amp;gt;PSEL.SDA = TWI_SDA;
    NRF_TWIM0-&amp;gt;FREQUENCY = 0x06400000;  //400kbps
    NRF_TWIM0-&amp;gt;ADDRESS = 0x0000078;
    NRF_TWIM0-&amp;gt;ENABLE = 6;
}

void WriteTwiCommand (uint8_t * Data)
{
    // copy data to TX buffer:
    for(int i = 0; i &amp;lt; BUFFER_SIZE; i++){
        tx_buf[0].buffer[i] = Data[i];
    }
    NRF_TWIM0-&amp;gt;TXD.MAXCNT = BUFFER_SIZE;
    NRF_TWIM0-&amp;gt;TXD.LIST = 1;
    NRF_TWIM0-&amp;gt;TXD.PTR = (uint32_t)tx_buf_p; //typecast pointer to uint32_t to get rid of warning.
    NRF_TWIM0-&amp;gt;TASKS_STARTTX = 1;
}
int main(void)
{
    initI2c();
    uint8_t data[BUFFER_SIZE] = {1,2}; // data you want to transmit
    WriteTwiCommand(data);
    while (true)
    {
        __WFE(); // CPU to sleep
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Anyways, why do you want to write directly to the registers like this? You should use the hardware driver in the SDK, it will save you a lot of trouble.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>