<?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>TWI Slave and APP_TIMER issues</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/54946/twi-slave-and-app_timer-issues</link><description>Hi, 
 I&amp;#39;m working on a custom bootloader which does DFU over I2C. As a fail safe mechanism I want to have a timer running that gets reset between each Image data block, so incase we dont get a new image data block in 5-10 seconds (unless we have received</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 04 Dec 2019 12:05:06 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/54946/twi-slave-and-app_timer-issues" /><item><title>RE: TWI Slave and APP_TIMER issues</title><link>https://devzone.nordicsemi.com/thread/223571?ContentTypeID=1</link><pubDate>Wed, 04 Dec 2019 12:05:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:21be04d2-77b5-49af-8d30-454e6ccc8cbe</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;This may be related to the app timer library. &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v16.0.0/migration.html?cp=6_1_1_8_2_1#migr_dfu_libs_app_timer"&gt;SDK 16 has introduced a new and improved version of the library app timer v2. &lt;/a&gt;A quick method to check if this is related to the driver is to backport the driver by downloading SDK 16, copy and paste the&amp;nbsp;&lt;span&gt;app_timer2.c and drv_rtc.c instead of&amp;nbsp;app_timer.c to your SDK 15 project see if the problem persists.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;regards&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Jared&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI Slave and APP_TIMER issues</title><link>https://devzone.nordicsemi.com/thread/223487?ContentTypeID=1</link><pubDate>Wed, 04 Dec 2019 08:13:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8243b30c-9417-4225-b803-9adc989cffd7</guid><dc:creator>AntonHellbe</dc:creator><description>&lt;p&gt;Hi Jared,&lt;/p&gt;
&lt;p&gt;You are correct that I dont want it to hit the timeout handler.&lt;/p&gt;
&lt;p&gt;What&amp;#39;s happening is that my timer reset is too quick, I stop it quickly and then start it immediately. This does not seem to reset the timer count, causing it to hit the timer timeout handler. And that apparently breaks the I2C transfers. Probably because I will keep trying to restart the timer each time a new I2C message is received.&lt;/p&gt;
&lt;p&gt;What I need to solve here is to reset the timer in a manner that ensures that the timer count is reset before I start it again.&lt;/p&gt;
&lt;p&gt;Any ideas how I can achieve that?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI Slave and APP_TIMER issues</title><link>https://devzone.nordicsemi.com/thread/223386?ContentTypeID=1</link><pubDate>Tue, 03 Dec 2019 15:05:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:40767113-97ca-4afa-ab6d-8d8b0130751d</guid><dc:creator>Jared</dc:creator><description>[quote user=""]But as soon as I transfer something it does not hit the handler and the I2C transfers stops.[/quote]
&lt;p&gt;&amp;nbsp;Could you elaborate on this? My understanding of your project is that you don&amp;#39;t want the timer to hit its handler when you transfer as this would cause a reset of the nRF. Instead, you would want to reset the timer after the transfer is complete in the&amp;nbsp;NRFX_TWIS_EVT_WRITE_DONE case.&amp;nbsp; Is the problem that the I2C transfer doesn&amp;#39;t start again after the timer is reset? again, it would be good to know where in the code it stops.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI Slave and APP_TIMER issues</title><link>https://devzone.nordicsemi.com/thread/223266?ContentTypeID=1</link><pubDate>Tue, 03 Dec 2019 10:13:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cfb51770-309f-473e-9ae0-58b21d2e8ae1</guid><dc:creator>AntonHellbe</dc:creator><description>&lt;p&gt;Also,&lt;/p&gt;
&lt;p&gt;Since I&amp;#39;m not using Segger Embedded Studio I&amp;#39;m working on getting the debugging working. I&amp;#39;m having some issues with Ozone. Will update you as soon as I get it to work..&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI Slave and APP_TIMER issues</title><link>https://devzone.nordicsemi.com/thread/222991?ContentTypeID=1</link><pubDate>Mon, 02 Dec 2019 10:23:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0c5d69ea-cc20-4184-a4da-0781f58148c6</guid><dc:creator>AntonHellbe</dc:creator><description>&lt;p&gt;Hi Jared.&lt;/p&gt;
&lt;p&gt;SDK V15.3, Softdevice V6.1.1.&lt;/p&gt;
&lt;p&gt;Timer module:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#include &amp;quot;comm_timer.h&amp;quot;
#include &amp;quot;app_timer.h&amp;quot;
#include &amp;quot;nrf_log.h&amp;quot;

app_timer_def(comm_timer);

static uint32_t communication_timeout_ms;

void comm_timer_init(on_communication_timeout comm_timeout, uint32_t timeout_ms)
{
    ret_code_t err_code;

    communication_timeout_ms = app_timer_ticks(timeout_ms);

    err_code = app_timer_create
    (
        &amp;amp;comm_timer,
        app_timer_mode_single_shot,
        comm_timeout
    );

    nrf_log_debug(&amp;quot;initializing comm timer returned: %d&amp;quot;, err_code);

    if(err_code != nrf_success)
    {
        nrf_log_info(&amp;quot;error initializing boot image timer&amp;quot;);
    }

}

void comm_timer_start(void)
{
    ret_code_t err_code;

    err_code = app_timer_start(
        comm_timer,
        communication_timeout_ms,
        null
    );
    nrf_log_debug(&amp;quot;starting comm timer returned err_code: %d&amp;quot;, err_code);

    if (err_code != nrf_success)
    {
        nrf_log_info(&amp;quot;failed to start comm_timer&amp;quot;);
    }
}

void comm_timer_stop(void)
{
    app_timer_stop(comm_timer);
}

void comm_timer_restart(void)
{
    comm_timer_stop();
    comm_timer_start();
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Callback (timeout handler) passed to comm_timer&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void communication_timeout(void * p_context)
{
    NRF_LOG_DEBUG(&amp;quot;Communication timeout!&amp;quot;);
}

&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;TWI Slave module:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#include &amp;quot;twi_slave.h&amp;quot;
#include &amp;quot;nrfx_twis.h&amp;quot;
#include &amp;quot;nrf_gpio.h&amp;quot;
#include &amp;quot;nrf_log.h&amp;quot;

#define ADDRESS (0x56U &amp;gt;&amp;gt; 1)
#define SDA_PIN 8
#define SCL_PIN 7

static const nrfx_twis_t instance = NRFX_TWIS_INSTANCE(0);
static uint8_t tx_buff[128];
static uint8_t rx_buff[128];
static size_t  tx_len;

static void twis_event_handler(nrfx_twis_evt_t const * const p_event);

void twi_slave_init(void)
{
    ret_code_t err_code;
    
    nrfx_twis_config_t config = 
    {
        .addr               = { ADDRESS },
        .scl                = SCL_PIN,
        .scl_pull           = (nrf_gpio_pin_pull_t) NRFX_TWIS_DEFAULT_CONFIG_SCL_PULL,
        .sda                = SDA_PIN,
        .sda_pull           = (nrf_gpio_pin_pull_t) NRFX_TWIS_DEFAULT_CONFIG_SDA_PULL,
        .interrupt_priority = NRFX_TWIS_DEFAULT_CONFIG_IRQ_PRIORITY
    };

    memset(rx_buff, 0, (sizeof(rx_buff) / sizeof(rx_buff[0])));
    memset(tx_buff, 0, (sizeof(tx_buff) / sizeof(tx_buff[0])));

    err_code = nrfx_twis_init(&amp;amp;instance, &amp;amp;config, twis_event_handler);

    if (err_code != NRF_SUCCESS)
    {
        NRF_LOG_DEBUG(&amp;quot;Error initializing TWI slave!&amp;quot;);
    }

    nrfx_twis_enable(&amp;amp;instance);
}

void twi_slave_uninit(void)
{
    nrfx_twis_uninit(&amp;amp;instance);
    nrfx_twis_disable(&amp;amp;instance);
}

void twi_slave_update_tx_buffer(const uint8_t * p_data, uint16_t length)
{
    NRF_LOG_DEBUG(&amp;quot;Sending response data&amp;quot;);
    uint8_t i;
    for (i = 0; i &amp;lt; length; i++)
    {
        tx_buff[i] = p_data[i];
    }
    tx_len = sizeof(uint8_t) * length;
}
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI Slave and APP_TIMER issues</title><link>https://devzone.nordicsemi.com/thread/222985?ContentTypeID=1</link><pubDate>Mon, 02 Dec 2019 10:15:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d0429430-482c-4b6a-84fd-5844a529cadd</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Sorry for the late reply,&lt;/p&gt;
&lt;p&gt;I have a couple questions I would like you to answer :) :&amp;nbsp;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Which SDK and Softdevice (if you are) version are you using?&lt;/li&gt;
&lt;li&gt;Could you provide a bit more code? I&amp;#39;m specifically interested in the initialization of the Timer and the I2C modules. Could you also share the timer handler, and how you reset the timer? I can make the case private if you prefer it.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Where exactly is the code stuck? Have you tried using the debugger and single step through the code?&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;best regards&lt;/p&gt;
&lt;p&gt;Jared&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>