<?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>Debugging Hardfault</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/24696/debugging-hardfault</link><description>Hi, 
 I&amp;#39;m working on an application with an accelerometer without SoftDevice (for the moment).
The accelerometer communicate in I2C. It send an interruption when a new sample is available (50Hz). 
 Some simple calculation are done on these values.</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 31 Aug 2017 12:57:25 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/24696/debugging-hardfault" /><item><title>RE: Debugging Hardfault</title><link>https://devzone.nordicsemi.com/thread/97191?ContentTypeID=1</link><pubDate>Thu, 31 Aug 2017 12:57:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7cc10317-47ea-4b82-a0fb-c168a6f8fa27</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Are you basing your application on any of the examples in the SDK? Which SDK version are you using? Are you using the Hardfault handling library? What TWI device are you interfacing? Could you upload your entire SES project for debugging?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Debugging Hardfault</title><link>https://devzone.nordicsemi.com/thread/97190?ContentTypeID=1</link><pubDate>Mon, 28 Aug 2017 14:06:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3eae25cf-42b8-4877-ba74-287ab2b7a1fe</guid><dc:creator>julienh</dc:creator><description>&lt;p&gt;In fact, I&amp;#39;m not checking the error code on &amp;quot;register get&amp;quot; function. I will add this check.&lt;/p&gt;
&lt;p&gt;You can see below these 2 functions.&lt;/p&gt;
&lt;p&gt;Accel read and register get (i2C) functions :&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;    void accel_read(void){
    ret_code_t err_code;

    uint8_t read;
    uint8_t valueL = 0,valueH = 0;
    int16_t x_raw, y_raw, z_raw;
    int32_t x, y,z;
    int32_t accel;
     
    // Read acceleration on all axis 
    register_get(H3LIS331DL_REG_OUT_X_L, &amp;amp;valueL);
    register_get(H3LIS331DL_REG_OUT_X_H, &amp;amp;valueH);
    x_raw =  (valueH&amp;lt;&amp;lt;8)|valueL;
    register_get(H3LIS331DL_REG_OUT_Y_L, &amp;amp;valueL);
    register_get(H3LIS331DL_REG_OUT_Y_H, &amp;amp;valueH);
    y_raw =  (valueH&amp;lt;&amp;lt;8)|valueL;
    register_get(H3LIS331DL_REG_OUT_Z_L, &amp;amp;valueL);
    register_get(H3LIS331DL_REG_OUT_Z_H, &amp;amp;valueH);
    z_raw =  (valueH&amp;lt;&amp;lt;8)|valueL;
    
    // Converting raw data to mg

    x = x_raw *3;
    y = y_raw *3;
    z = z_raw *3;

    //NRF_LOG_INFO(&amp;quot;Accel x %i, %i, %i \r\n&amp;quot;, x,y,z);

    accel = sqrt(x*x + y*y + z*z);

   //add accel value to a buffer. When the buffer is full, detect the peak.
    peak_detection(accel); 
}




static ret_code_t register_get(uint8_t reg, uint8_t * pval)
{
  uint32_t start;

  // Write register address
  m_xfer_done = false;
  nrf_drv_twi_tx(&amp;amp;m_twi, SLAVE_ADDRESS, &amp;amp;reg, 1, true);
  start = NRF_RTC1-&amp;gt;COUNTER;
  while ((m_xfer_done == false) &amp;amp;&amp;amp; ((NRF_RTC1-&amp;gt;COUNTER - start) &amp;lt; TWI_TIMEOUT) ) ;

  if (m_xfer_done == false)
    return NRF_ERROR_TIMEOUT;

  // Read register value
  m_read_done = false;
  nrf_drv_twi_rx(&amp;amp;m_twi, SLAVE_ADDRESS, pval, 1);
  start = NRF_RTC1-&amp;gt;COUNTER;
  while ((m_read_done == false) &amp;amp;&amp;amp; ((NRF_RTC1-&amp;gt;COUNTER - start) &amp;lt; TWI_TIMEOUT) ) ;

  if (m_read_done == false)
    return NRF_ERROR_TIMEOUT;
  
  return NRF_SUCCESS;
}
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Debugging Hardfault</title><link>https://devzone.nordicsemi.com/thread/97189?ContentTypeID=1</link><pubDate>Mon, 28 Aug 2017 13:41:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:161b1a37-3689-487b-83a3-622d9d5259c7</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Are you checking error codes from all function calls? How often do you see the hardfault? Could you post code snippets from the accel_read() and register_get() functions?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>