<?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 slave implementation</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/76127/i2c-slave-implementation</link><description>Dear community, 
 I need to operate a BM833A as I2C slave and to do so, I performed the following steps: 
 I modfied my sdk_config.h and set TWIS_ENABLED and NRFX_TWIS_ENABLED identically following hint at: 
 devzone.nordicsemi.com/.../merge-twis-i2c</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 16 Jun 2021 10:30:38 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/76127/i2c-slave-implementation" /><item><title>RE: I2C slave implementation</title><link>https://devzone.nordicsemi.com/thread/315567?ContentTypeID=1</link><pubDate>Wed, 16 Jun 2021 10:30:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:09a7344f-8020-4ca0-b017-1f2566292271</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello Richard,&lt;/p&gt;
[quote user="RichardHdrd"]Either forum or my browser are not allowing me to reply on a lower thread level (no message buttons there), so I hope you still can see my post at top level here:[/quote]
&lt;p&gt;No problem, I still see your comments here.&lt;br /&gt;I have heard other users mention this happening earlier.&amp;nbsp;The issue is already reported internally, so we will examine this more closely and implement a fix, sorry for the inconvenience.&lt;br /&gt;A &amp;#39;workaround&amp;#39; to this is to click on the timestamp of the comment you would like to reply to, this should make the buttons appear again.&lt;/p&gt;
[quote user="RichardHdrd"]But still, I get no reaction on the I2C data line, while clock line is operating with master-bus speed of 115k.[/quote]
&lt;p&gt;What is your TWI master doing at this time? Is it initiating any transfers, or trying to read out a section of the TWI slave&amp;#39;s memory?&lt;br /&gt;The TWI slave can not initiate a transfer, this has to be done by the TWI master. The TWI slave can only do as instructed by the master. Is your TWI master attempting to read from a particular register, for example?&lt;br /&gt;If you look into the main.c of the TWI master and TWI simulated EEPROM slave example I referenced in my previous comment, you can see how TWI master communication can be initiated.&amp;nbsp;&lt;/p&gt;
[quote user="RichardHdrd"]for a first test using synchronous mode of the following given example:[/quote]
&lt;p&gt;I notice in your code that you are in fact not following the instructions / example of the TWIS driver in synchronous mode, that you reference. Why is that? Please try this again, with the full example (the TWIS slave should also be prepared for RX events, and you will need to check whether the driver is already busy when using it in synchronous mode.&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C slave implementation</title><link>https://devzone.nordicsemi.com/thread/315406?ContentTypeID=1</link><pubDate>Tue, 15 Jun 2021 13:04:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9b477488-1efc-4c16-8a1d-8c084c21f81b</guid><dc:creator>RichardHdrd</dc:creator><description>&lt;p&gt;Dear Karl,&lt;/p&gt;
&lt;p&gt;Either forum or my browser are not allowing me to reply on a lower thread level (no message buttons there), so I hope you still can see my post at top level here:&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;br /&gt;For a first effort I took the following example (and also telling, I use SDK 17.0.2, Segger Embedded Studio, S140 on a BM833A (52811 nordic) hardware), for a first test using synchronous mode of the following given example:&lt;br /&gt;&lt;br /&gt;&lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fsdk_nrf5_v17.0.2%2Fhardware_driver_twis_slave.html"&gt;infocenter.nordicsemi.com/index.jsp&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Following your suggestion, I managed to remove all legacy driver stuff with help of given page:&lt;br /&gt;&lt;br /&gt;&lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v15.0.0%2Fgroup__nrfx__twis.html"&gt;infocenter.nordicsemi.com/index.jsp&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;This results in the following relevant code, which compiles and runs with continuous debug-output:&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;(...)
#include &amp;quot;nrfx_twis.h&amp;quot;

(...)
APP_TIMER_DEF(m_bsp_tmr);

(...)
static const nrfx_twis_t m_twi = NRFX_TWIS_INSTANCE(0);

/**
 * @brief TWI initialization.
 */
void twi_init (void)
{
    ret_code_t err_code;

    const nrfx_twis_config_t twi_config = {
       .addr               = {7,0},
       .scl                = 27,
       .scl_pull           = 3, /*=&amp;gt; Pull up*/ 
       .sda                = 26,
       .sda_pull           = 3, /*=&amp;gt; Pull up*/ 
       .interrupt_priority = APP_IRQ_PRIORITY_HIGH
    };

    //err_code = nrf_drv_twis_init(&amp;amp;m_twi, &amp;amp;twi_config, twis_event_handler);
    err_code = nrfx_twis_init(&amp;amp;m_twi, &amp;amp;twi_config, NULL);
    APP_ERROR_CHECK(err_code);

    nrfx_twis_enable(&amp;amp;m_twi);
}


/**@brief Function for initializing the timer. */
static void timer_init(void)
{
    ret_code_t err_code = app_timer_init();
    APP_ERROR_CHECK(err_code);
}


/**@brief Function for initializing the nrf log module. */
static void log_init(void)
{
    ret_code_t err_code = NRF_LOG_INIT(NULL);
    APP_ERROR_CHECK(err_code);

    NRF_LOG_DEFAULT_BACKENDS_INIT();
}

/**@brief Function for initializing power management.
 */
static void power_management_init(void)
{
    ret_code_t err_code;
    err_code = nrf_pwr_mgmt_init();
    APP_ERROR_CHECK(err_code);
}

/**@brief Function for handling the idle state (main loop).
 *
 * @details Handles any pending log operations, then sleeps until the next event occurs.
 */
static void idle_state_handle(void)
{
    if (NRF_LOG_PROCESS() == false)
    {
        nrf_pwr_mgmt_run();
    }
}

/**@brief Handle events from button timer.
 *
 * @param[in]   p_context   parameter registered in timer start function.
 */
static void m_timer_handler(void * p_context)
{
     uint16_t count=0;
     char txbuffer[32];
     strcpy(txbuffer, &amp;quot;ready!\r\n&amp;quot;);
     uint16_t len=strlen(txbuffer);
          
     if(len&amp;gt;0)
     {
       NRF_LOG_INFO(&amp;quot;Sending Data: %d.&amp;quot;, len);
       ret_code_t err_code = nrfx_twis_tx_prepare(&amp;amp;m_twi, txbuffer, len);   //also tried len+1
       APP_ERROR_CHECK(err_code);

       while (nrfx_twis_is_busy(&amp;amp;m_twi) &amp;amp;&amp;amp; count&amp;lt;35000)
       {
           nrf_delay_us(10);
           count++;
       }
       NRF_LOG_INFO(&amp;quot;Loop hops: %d.&amp;quot;, count);                               //always reports 0
       //memcpy((void*)txbuffer, 0, 32);
     }
}

int main(void)
{
    log_init();
    twi_init();
    //enable obtaining ms,us from CPU since firmware start
    timer_init();
    power_management_init();
    
    uint32_t timeout_ticks = APP_TIMER_TICKS(500);
    ret_code_t err_code = app_timer_create(&amp;amp;m_bsp_tmr, APP_TIMER_MODE_REPEATED, m_timer_handler);
    APP_ERROR_CHECK(err_code);
    app_timer_start(m_bsp_tmr, timeout_ticks, NULL);

    // Enter main loop.
    for (;;)
    {
        idle_state_handle();
    }
}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;But still, I get no reaction on the I2C data line, while clock line is operating with master-bus speed of 115k.&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;&lt;br /&gt;Richard&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C slave implementation</title><link>https://devzone.nordicsemi.com/thread/315321?ContentTypeID=1</link><pubDate>Tue, 15 Jun 2021 08:56:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:65512a33-0bc3-4fc4-85f7-cc108f16f056</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello Richard,&lt;/p&gt;
[quote user="RichardHdrd"]&lt;p&gt;Sorry, that is not the case.&lt;/p&gt;
&lt;p&gt;The BM833A contains a nordic 52811 chip. This platform shall act as I2C (TWI) slave.Programming this is the issue of my inquiry here.&lt;/p&gt;[/quote]
&lt;p&gt;Thank you for clarifying this.&amp;nbsp;&lt;/p&gt;
[quote user="RichardHdrd"]What you see is the code that I used to drive the BM833A (52811 nordic) hardware to send data as I2C slave to that other hardware platform.[/quote]
&lt;p&gt;It would also be good if you could share your entire main.c code, either through the&amp;nbsp;&lt;em&gt;Insert -&amp;gt; Code&amp;nbsp;&lt;/em&gt;option, or by uploading the main.c file as a whole. In your current code, I see no mention of your twis_event_handler, except for in the initialization function - so I only know it exists, but not its contents.&lt;br /&gt;It might also be helpful for you to take a look at &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.0.2/twi_master_with_twis_slave_example.html"&gt;the&amp;nbsp;&lt;em&gt;eeprom_simulator.c&lt;/em&gt; file of the TWI master with TWIS slave example from the SDK&lt;/a&gt;. This file demonstrates how to implement a TWI slave on the nRF side.&lt;/p&gt;
[quote user="RichardHdrd"]Currently, there are no other slaves connected to the I2C-bus, but the plan is (once the single slave works) to connect five more BM833A slaves to the I2C-bus.[/quote]
&lt;p&gt;This should be no problem, since the bus master will address each slave separately.&lt;br /&gt;&lt;br /&gt;Could you confirm for me which SDK you are using?&lt;br /&gt;I see now that one of the API reference links you provided is for SDK v12, which does not contain the nrfx drivers.&lt;/p&gt;
[quote user="RichardHdrd"]&lt;p&gt;The macro cannot be removed, as it is required in the main.c code:&lt;/p&gt;
&lt;div&gt;&lt;/div&gt;&lt;blockquote&gt;&lt;div&gt;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/76127/i2c-slave-implementation"&gt;RichardHdrd said:&lt;/a&gt;&lt;/div&gt;&lt;div&gt;static const nrf_drv_twis_t m_twi = NRF_DRV_TWIS_INSTANCE(TWIS_INSTANCE_ID);&lt;/div&gt;&lt;/blockquote&gt;&lt;div&gt;&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;So how could I succeed in removing?&lt;/p&gt;[/quote]
&lt;p&gt;Yes, you must still declare an TWIS instance, but you may do so using the NRFX version of the macro:&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fsdk_nrf5_v17.0.2%2Fgroup__nrfx__twis.html&amp;amp;anchor=gacbd2b67adcc8746a5c351e0fc0494112"&gt;NRFX_TWIS_INSTANCE&lt;/a&gt;.&lt;br /&gt;Please replace this macro call with the nrfx version, and see if it resolves the broken build issue.&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C slave implementation</title><link>https://devzone.nordicsemi.com/thread/315298?ContentTypeID=1</link><pubDate>Tue, 15 Jun 2021 08:10:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fc0f8fce-724c-4f79-8b28-80ee597d299f</guid><dc:creator>RichardHdrd</dc:creator><description>&lt;p&gt;Dear Karl,&lt;/p&gt;
&lt;p&gt;I tried removing legacy defines&lt;/p&gt;
&lt;p&gt;removed all sdk config from:&lt;/p&gt;
&lt;p&gt;// &amp;lt;e&amp;gt; TWIS_ENABLED - nrf_drv_twis - TWIS peripheral driver - legacy layer&lt;/p&gt;
&lt;p&gt;(...until first...)&lt;/p&gt;
&lt;p&gt;// &amp;lt;/e&amp;gt;&lt;/p&gt;
&lt;p&gt;This results in a broken config.&lt;/p&gt;
&lt;p&gt;Compiling, I get (in nrfx_twis.h):&lt;/p&gt;
&lt;p&gt;&amp;lsquo;NRF_TWISTWIS_INSTANCE_ID&amp;rsquo; undeclared here (not in a function); did you mean &amp;lsquo;NRF_DRV_TWIS_INSTANCE&amp;rsquo;?&lt;/p&gt;
&lt;p&gt;in definition of macro &amp;lsquo;NRFX_CONCAT_2_&amp;rsquo;&lt;/p&gt;
&lt;p&gt;in expansion of macro &amp;lsquo;NRFX_CONCAT_2&amp;rsquo;&lt;/p&gt;
&lt;p&gt;in expansion of macro &amp;lsquo;NRFX_TWIS_INSTANCE&amp;rsquo;&lt;/p&gt;
&lt;p&gt;in expansion of macro &amp;lsquo;NRF_DRV_TWIS_INSTANCE&amp;rsquo;&lt;/p&gt;
&lt;p&gt;(...plus second, similar error)&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The referenced Code in nrfx_twis.h:&lt;/p&gt;
&lt;p&gt;/** @brief Macro for creating a TWIS driver instance. */&lt;br /&gt;#define NRFX_TWIS_INSTANCE(id)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; \&lt;br /&gt;{&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; \&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; .p_reg&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = NRFX_CONCAT_2(NRF_TWIS, id),&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; \&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; .drv_inst_idx = NRFX_CONCAT_3(NRFX_TWIS, id, _INST_IDX), \&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;The macro cannot be removed, as it is required in the main.c code:&lt;/p&gt;
[quote userid="103815" url="~/f/nordic-q-a/76127/i2c-slave-implementation"]static const nrf_drv_twis_t m_twi = NRF_DRV_TWIS_INSTANCE(TWIS_INSTANCE_ID);[/quote]
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;So how could I succeed in removing?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Richard&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C slave implementation</title><link>https://devzone.nordicsemi.com/thread/314598?ContentTypeID=1</link><pubDate>Thu, 10 Jun 2021 06:24:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a149dea8-219a-4e27-ba6b-eeb9a6dc73fa</guid><dc:creator>RichardHdrd</dc:creator><description>&lt;p&gt;Dear Karl,&lt;/p&gt;
[quote userid="87869" url="~/f/nordic-q-a/76127/i2c-slave-implementation/314217#314217"]If I have understood your intentions correctly, you intend for the nRF to be the TWI master, and the BM833A to be the TWI slave - is this correct?[/quote]
&lt;p&gt;Sorry, that is not the case.&lt;/p&gt;
&lt;p&gt;The BM833A contains a nordic 52811 chip. This platform shall act as I2C (TWI) slave.Programming this is the issue of my inquiry here.&lt;/p&gt;
&lt;p&gt;The I2C master (also supplying the clock at 115kB) is on another hardware platform and has been functionally tested and shown proof of work with other I2C slaves, independantly and before.&lt;/p&gt;
&lt;p&gt;What you see is the code that I used to drive the BM833A (52811 nordic) hardware to send data as I2C slave to that other hardware platform.&lt;/p&gt;
&lt;p&gt;Currently, there are no other slaves connected to the I2C-bus, but the plan is (once the single slave works) to connect five more BM833A slaves to the I2C-bus.&lt;/p&gt;
&lt;p&gt;As you suggested, I will try to remove legacy mode config and report back.&lt;/p&gt;
&lt;p&gt;Thank you,&lt;/p&gt;
&lt;p&gt;Richard&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C slave implementation</title><link>https://devzone.nordicsemi.com/thread/314217?ContentTypeID=1</link><pubDate>Tue, 08 Jun 2021 12:45:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:efa1a36f-408c-443b-ab95-bf9c789ba910</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello Richard,&lt;/p&gt;
[quote user=""]&lt;p&gt;I need to operate a BM833A as I2C slave and to do so, I performed the following steps:&lt;/p&gt;
&lt;p&gt;I modfied my sdk_config.h and set TWIS_ENABLED and NRFX_TWIS_ENABLED identically following hint at:&lt;/p&gt;[/quote][quote user=""]Any suggestions on corrections?[/quote]
&lt;p&gt;If I have understood your intentions correctly, you intend for the nRF to be the TWI master, and the BM833A to be the TWI slave - is this correct?&lt;br /&gt;If so, you will need to setup the nRF to use the TWI&lt;em&gt;M&lt;/em&gt; driver, for it to be in the master configuration. Currently, it seems that you have configured your nRF to be a TWI slave, which will need a TWI Master to be present on the bus, for it to work.&lt;br /&gt;If you wish to make the nRF the bus master, you could start out by taking a look at &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.0.2/twi_scanner_example.html"&gt;the TWI Scanner example&lt;/a&gt;&amp;nbsp;- if the scanner example functions as expected, it will confirm that the wiring and hardware connections between the master and slave device is correct. Then, you can move over to implementing the TWIM driver&amp;#39;s behavior.&lt;/p&gt;
[quote user=""](Either completely remove the legacy (non NRFX_...) for TWI(S) or set them equal to the NRFX_TWIS_... definitions.)[/quote]
&lt;p&gt;You should always completely remove the legacy defines from the sdk_config when you intend to use the nrfx driver, because the nrfx enable will be overwritten by the apply_old_config file if the legacy definitions are left&amp;nbsp;&lt;em&gt;defined&lt;/em&gt; (their defined value does not matter).&lt;/p&gt;
[quote user=""]1) SCL is provided with 115k clock from master[/quote]
&lt;p&gt;Where is this clock being supplied from? The clock should be supplied by the bus master, but it seems to me that your bus currently does not have a master, so I am not sure what is happening here. Where else in your application is the definition of the SCL pin used?&lt;br /&gt;&lt;br /&gt;For future reference, please use the&amp;nbsp;&lt;em&gt;Insert -&amp;gt; Code&amp;nbsp;&lt;/em&gt;option when sharing code here on DevZone.&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>