<?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 problem</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/75892/twi-problem</link><description>Hi forum, 
 I am working on nrf52832 custom board, using sdk 15.0.0. 
 I referred example/peripherals/twi_sesnor example as reference. I am trying to interface LIS2dw12 with nrf52832. 
 While debugging, I found that the board gets stuck in the &amp;quot; while</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 03 Jun 2021 11:59:41 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/75892/twi-problem" /><item><title>RE: Twi problem</title><link>https://devzone.nordicsemi.com/thread/313394?ContentTypeID=1</link><pubDate>Thu, 03 Jun 2021 11:59:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e42912ee-4375-4986-8d92-21ecd65a8c87</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Is the flag declared as static volatile? Can you set a breakpoint at 27 and upload a screenshot from debug view that shows that the handler is called and the variable is set to true. Also, what other modules/peripherals do you use? Is the Softdevice used?&lt;/p&gt;
&lt;p&gt;regards&lt;/p&gt;
&lt;p&gt;Jared&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Twi problem</title><link>https://devzone.nordicsemi.com/thread/313253?ContentTypeID=1</link><pubDate>Thu, 03 Jun 2021 06:05:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:86291125-18c4-4d4a-b69b-3710bd777eb8</guid><dc:creator>dewal</dc:creator><description>&lt;p&gt;Hi forum,&lt;/p&gt;
&lt;p&gt;I tried to change interrupt priority to low it works once. after redumped code its not working.&lt;/p&gt;
&lt;p&gt;please help me to slove this problem.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Twi problem</title><link>https://devzone.nordicsemi.com/thread/313117?ContentTypeID=1</link><pubDate>Wed, 02 Jun 2021 12:55:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7ac8960f-9f47-4a26-b35b-cf856f4600a5</guid><dc:creator>dewal</dc:creator><description>&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;//
// TWI events handler.
//
void twi_handler(nrf_drv_twi_evt_t const * p_event, void * p_context)
{
    switch (p_event-&amp;gt;type)
    {
        // TWI event completed
        // If data was being read, jump to the data handler
        // Otherwise, assume it was a transmit and just indicate transfer is done
        case NRF_DRV_TWI_EVT_DONE:
            if (p_event-&amp;gt;xfer_desc.type == NRF_DRV_TWI_XFER_RX) // Reading data
            {
              if (reg[0] == HTS221_WHO_AM_I) // Reading from HTS221 WHO_AM_I register
              id_handler(m_sample);
             if (reg[0] == HTS221_CTRL_REG1) // Reading CTRL_REG1
                reg1_handler(m_sample);
              if (reg[0] == 0xB0) // Reading the calibration data
               calibration_handler(calibration_regs);
              if (reg[0] == 0xAA) // Reading the temperature registers
                temperature_handler(raw_temp);
             if (reg[0] == HTS221_STATUS_REG) // Reading the status register
                status_handler(m_sample);
            if (reg[0] == 0xA8)  // Reading the humidity registers
               humidity_handler(raw_hum);
            }
           m_xfer_done = true;
        // m_xfer_done = false;
            break;
        default:
            break;
    }
}

//
// TWI initialization.
//
void twi_init (void)
{
    ret_code_t err_code;

    const nrf_drv_twi_config_t twi_hts221_config = {
       .scl                =SCL_PIN,
       .sda                =SDA_PIN,
       .frequency          = NRF_DRV_TWI_FREQ_100K,
       .interrupt_priority = APP_IRQ_PRIORITY_HIGH,
       .clear_bus_init     = false
    };
 
    err_code = nrf_drv_twi_init(&amp;amp;m_twi, &amp;amp;twi_hts221_config, twi_handler, NULL);
    APP_ERROR_CHECK(err_code);
    printf(&amp;quot;init: %d\n&amp;quot;,err_code);

    nrf_drv_twi_enable(&amp;amp;m_twi);

    //
    // read calibration registers
    //
    reg[0]=0xB0; // 1st Register address of the calibration registers
    // Note bit 7 is set for register address incrementing. 0x30 | 0x80
    err_code = nrf_drv_twi_tx(&amp;amp;m_twi, HTS221_ADDR, reg, sizeof(reg),true);
    APP_ERROR_CHECK(err_code);
    // Wait for transmit to complete
    while (m_xfer_done == false);
    // Reset TWI event complete flag
    m_xfer_done = false;
    // Read 16 bytes of raw calibration data from 0x30-3F
    // Data will be returned via twi event handler
    err_code = nrf_drv_twi_rx(&amp;amp;m_twi, HTS221_ADDR, calibration_regs, sizeof(calibration_regs));
    APP_ERROR_CHECK(err_code);

}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;if anymore required let me know. few days ago I was tested this code it works fine.it gives us temperature and humidity exact value match with surrounding temp.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Twi problem</title><link>https://devzone.nordicsemi.com/thread/313098?ContentTypeID=1</link><pubDate>Wed, 02 Jun 2021 12:30:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0c45d569-ecae-4a87-a80e-956e47ec1b31</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Could you post more of your code?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Twi problem</title><link>https://devzone.nordicsemi.com/thread/313073?ContentTypeID=1</link><pubDate>Wed, 02 Jun 2021 11:39:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9085c744-8e96-4a01-9bd9-9c4709819798</guid><dc:creator>dewal</dc:creator><description>&lt;p&gt;thanks for reply,&lt;/p&gt;
&lt;p&gt;i checked interrupt handler is called. I checked in register setting Event is triggred.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1622633881952v2.png" alt=" " /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Twi problem</title><link>https://devzone.nordicsemi.com/thread/313046?ContentTypeID=1</link><pubDate>Wed, 02 Jun 2021 09:20:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5a989aca-43bf-4020-beae-e7e4b1efd0bd</guid><dc:creator>T IJ</dc:creator><description>&lt;p&gt;Can you confirm that the interrupt handler is called? Could it be that there is an error in the communication and that the done event is not triggered&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Twi problem</title><link>https://devzone.nordicsemi.com/thread/313043?ContentTypeID=1</link><pubDate>Wed, 02 Jun 2021 09:13:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5da39333-e155-47f7-af76-e06803c40e13</guid><dc:creator>dewal</dc:creator><description>&lt;p&gt;thanks for reply,&lt;/p&gt;
&lt;p&gt;this flag is true in interrupt handler and this variable declared as volatile.&lt;/p&gt;
&lt;p&gt;still stuck.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Twi problem</title><link>https://devzone.nordicsemi.com/thread/313037?ContentTypeID=1</link><pubDate>Wed, 02 Jun 2021 08:36:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:438f54bf-c07a-495b-bd15-ec1e5c330ab2</guid><dc:creator>T IJ</dc:creator><description>&lt;p&gt;Are you setting the variable to true in the interrupt handler and is the variable declared volatile?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>