<?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>Getting x,y,z values from BMX055 using i2C</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/70421/getting-x-y-z-values-from-bmx055-using-i2c</link><description>So, I am quite beginer with programming and working with this sensors and nrf, So I need your guys help. 
 I am trying to get the x,y,z values from the accelerometer of BMX055 IMU sensor. So, I did not used BMX055 drivers. But the issue here is that I</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 20 Jan 2021 11:21:36 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/70421/getting-x-y-z-values-from-bmx055-using-i2c" /><item><title>RE: Getting x,y,z values from BMX055 using i2C</title><link>https://devzone.nordicsemi.com/thread/290222?ContentTypeID=1</link><pubDate>Wed, 20 Jan 2021 11:21:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2c3ccf7c-7dfd-4934-89ec-a1dce0c04de1</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;You should change this code in&amp;nbsp;bmxme_register_read() and&amp;nbsp;bmxme_register_write():&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;err_code = nrf_drv_twi_tx(&amp;amp;m_twi, BMA2x2_I2C_ADDR1 , &amp;amp;register_address, 1, true);
	  
//Wait for the transmission to get completed
while (m_xfer_done == false){}

// If transmission was not successful, exit the function with false as return value
if (NRF_SUCCESS != err_code)
{
    return false;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;You need to check the error before waiting for the flag. With the current code, if there is an error preventing the transfer from starting, your application will block waiting for the event indicating that the transfer completed, before it is able to detect that the transfer never started.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Getting x,y,z values from BMX055 using i2C</title><link>https://devzone.nordicsemi.com/thread/290205?ContentTypeID=1</link><pubDate>Wed, 20 Jan 2021 10:49:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2a2c1d45-21f7-47d0-902d-d03a5eff0b6d</guid><dc:creator>syed</dc:creator><description>&lt;p&gt;well now the output is showing in NRF log. the deferred was to be disabled.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;But now i am stuck in Reading the x,y,z values from BMX055 sensor.&lt;/p&gt;
&lt;p&gt;It just goes till&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;line 42 : NRF_LOG_INFO(&amp;quot;Reading Values from ACC&amp;quot;);&amp;nbsp;&amp;nbsp;&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;but the verification and initialization is successful. It means that my read and write functions of i2c are working fine. But to read values, that function is having some issue.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Can you have a look, Your support would highly be appreciated&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Getting x,y,z values from BMX055 using i2C</title><link>https://devzone.nordicsemi.com/thread/289109?ContentTypeID=1</link><pubDate>Thu, 14 Jan 2021 09:49:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ae7ca332-c135-4454-b2ab-66a178c89cac</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Have you checked if the application runs correctly at all, or is it &amp;quot;stuck&amp;quot; in a reset-loop? If you add blinking of LEDs in your application, that would indicate if it is running correctly apart from the logging.&lt;/p&gt;
&lt;p&gt;I would also recommend you to build the application with the Debug configuration enabled, and run the debugger to see if there are any errors reported or HardFaults happening.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Which SDK version are you using?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Getting x,y,z values from BMX055 using i2C</title><link>https://devzone.nordicsemi.com/thread/288950?ContentTypeID=1</link><pubDate>Wed, 13 Jan 2021 14:03:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:96672d8b-ed20-469b-b551-278bb1702376</guid><dc:creator>syed</dc:creator><description>&lt;p&gt;No, I don&amp;#39;t even have this in output &lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;TWI accelerometer reading started.&amp;quot;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;yes I have already enable&amp;nbsp;NRF_LOG_ENABLED and&amp;nbsp;NRF_LOG_BACKEND_UART_ENABLED.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I also tried this&amp;nbsp;&lt;strong&gt;&lt;em&gt;while(NRF_LOG_PROCESS() == true);&lt;/em&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;but still the it is not showing anything.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Getting x,y,z values from BMX055 using i2C</title><link>https://devzone.nordicsemi.com/thread/288943?ContentTypeID=1</link><pubDate>Wed, 13 Jan 2021 13:47:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2252f949-c713-4295-8381-6aa4e302ee96</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Do you get &lt;em&gt;any&lt;/em&gt; output on the serial terminal, for instance the line &amp;quot;&lt;span&gt;TWI accelerometer reading started.&amp;quot;?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;If not, have you enabled NRF_LOG and the UART backend in your sdk_config.h file?&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;// &amp;lt;e&amp;gt; NRF_LOG_ENABLED - nrf_log - Logger
//==========================================================
#ifndef NRF_LOG_ENABLED
#define NRF_LOG_ENABLED 1
#endif

// &amp;lt;e&amp;gt; NRF_LOG_BACKEND_UART_ENABLED - nrf_log_backend_uart - Log UART backend
//==========================================================
#ifndef NRF_LOG_BACKEND_UART_ENABLED
#define NRF_LOG_BACKEND_UART_ENABLED 1
#endif&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;If you have the logger configured to use deferred mode (NRF_LOG_DEFERRED set to 1), you also needs to process the log in your main while-loop:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;while(NRF_LOG_PROCESS() == true);

//or:

NRF_LOG_FLUSH();

&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Jørgen&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Getting x,y,z values from BMX055 using i2C</title><link>https://devzone.nordicsemi.com/thread/288942?ContentTypeID=1</link><pubDate>Wed, 13 Jan 2021 13:43:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9989fe7d-4387-4eb0-8cda-60f42b974634</guid><dc:creator>syed</dc:creator><description>&lt;p&gt;Sorry I didnt notice that.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So, this is bmx.c file :&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#include &amp;lt;stdbool.h&amp;gt;
#include &amp;lt;stdint.h&amp;gt;
#include &amp;lt;string.h&amp;gt;
#include &amp;quot;nrf_drv_twi.h&amp;quot;
#include &amp;quot;bma2x2.h&amp;quot;




//Initializing TWI0 instance
#define TWI_INSTANCE_ID     0

// A flag to indicate the transfer state
static volatile bool m_xfer_done = false;


// Create a Handle for the twi communication
static const nrf_drv_twi_t m_twi = NRF_DRV_TWI_INSTANCE(TWI_INSTANCE_ID);




//Event Handler
void twi_handler(nrf_drv_twi_evt_t const * p_event, void * p_context)
{
    //Check the event to see what type of event occurred
    switch (p_event-&amp;gt;type)
    {
        //If data transmission or receiving is finished
	case NRF_DRV_TWI_EVT_DONE:
        m_xfer_done = true;//Set the flag
        break;
        
        default:
        // do nothing
          break;
    }
} 



//Initialize the TWI as Master device
void twi_master_init(void)
{
    ret_code_t err_code;

    // Configure the settings for twi communication
    const nrf_drv_twi_config_t twi_config = {
       .scl                = TWI_SCL_M,  //SCL Pin
       .sda                = TWI_SDA_M,  //SDA Pin
       .frequency          = NRF_DRV_TWI_FREQ_400K, //Communication Speed
       .interrupt_priority = APP_IRQ_PRIORITY_HIGH, //Interrupt Priority(Note: if using Bluetooth then select priority carefully)
       .clear_bus_init     = false //automatically clear bus
    };


    //A function to initialize the twi communication
    err_code = nrf_drv_twi_init(&amp;amp;m_twi, &amp;amp;twi_config, twi_handler, NULL);
    APP_ERROR_CHECK(err_code);
    
    //Enable the TWI Communication
    nrf_drv_twi_enable(&amp;amp;m_twi);
}



/*
   A function to write a Single Byte to bmx&amp;#39;s internal Register
*/ 
bool bmxme_register_write(uint8_t register_address, uint8_t value)
{
    ret_code_t err_code;
    uint8_t tx_buf[BMA2x2_GEN_READ_WRITE_LENGTH+1];
	
    //Write the register address and data into transmit buffer
    tx_buf[0] = register_address;
    tx_buf[1] = value;

    //Set the flag to false to show the transmission is not yet completed
    m_xfer_done = false;
    
    //Transmit the data over TWI Bus
    err_code = nrf_drv_twi_tx(&amp;amp;m_twi, BMA2x2_I2C_ADDR1, tx_buf, BMA2x2_GEN_READ_WRITE_LENGTH+1, false);
    
    //Wait until the transmission of the data is finished
    while (m_xfer_done == false)
    {
      }

    // if there is no error then return true else return false
    if (NRF_SUCCESS != err_code)
    {
        return false;
    }
    
    return true;	
}
 
bool bmxme_verify_product_id(void)
{
    uint8_t who_am_i; // create a variable to hold the who am i value


    if (bmxme_register_read(I_AM_BMX055_ACC, &amp;amp;who_am_i, 1))
    {
        if (who_am_i != I_AM_BMX055_ACC)
        {
            return false;
        }
        else
        {
            return true;
        }
    }
    else
    {
        return false;
    }

}
/*
  Function to initialize the bmx055
*/ 
bool bmxme_init(void)
{   
  bool transfer_succeeded = true;
    
  //Check the id to confirm that we are communicating with the right device
  transfer_succeeded &amp;amp;= bmxme_verify_product_id();
    
  if(bmxme_verify_product_id() == false)
    {
    return false;
      }

  // Set the registers with the required values, see the datasheet to get a good idea of these values
  (void)bmxme_register_write(BMA2x2_MODE_CTRL_ADDR , 0x00);
  (void)bmxme_register_write(BMA2x2_LOW_NOISE_CTRL_ADDR , 0x00);  
  (void)bmxme_register_write(BMA2x2_DATA_CTRL_ADDR , 0x40); 
  (void)bmxme_register_write(BMA2x2_BW_SELECT_ADDR , 0x08);
  (void)bmxme_register_write(BMA2x2_RANGE_SELECT_ADDR , 0x08);  

  return transfer_succeeded;
}


/*
  A Function to read data from the bmx055
*/ 
bool bmxme_register_read(uint8_t register_address, uint8_t * destination, uint8_t number_of_bytes)
{
    ret_code_t err_code;

    //Set the flag to false to show the receiving is not yet completed
    m_xfer_done = false;
    
    // Send the Register address where we want to write the data
    err_code = nrf_drv_twi_tx(&amp;amp;m_twi, BMA2x2_I2C_ADDR1 , &amp;amp;register_address, 1, true);
	  
    //Wait for the transmission to get completed
    while (m_xfer_done == false){}
    
    // If transmission was not successful, exit the function with false as return value
    if (NRF_SUCCESS != err_code)
    {
        return false;
    }

    //set the flag again so that we can read data from the bmx055&amp;#39;s internal register
    m_xfer_done = false;
	  
    // Receive the data from the bmx055
    err_code = nrf_drv_twi_rx(&amp;amp;m_twi, BMA2x2_I2C_ADDR1, destination, number_of_bytes);
		
    //wait until the transmission is completed
    while (m_xfer_done == false){}
	
    // if data was successfully read, return true else return false
    if (NRF_SUCCESS != err_code)
    {
        return false;
    }
    
    return true;
}


/*
  A Function to read accelerometer&amp;#39;s values from the internal registers of MPU6050
*/ 
bool bmxme_ReadAcc( int16_t *pACC_X , int16_t *pACC_Y , int16_t *pACC_Z )
{
  uint8_t xaxis_buf[2];
  uint8_t yaxis_buf[2];
  uint8_t zaxis_buf[2];
  bool ret = false;		
  
  if(bmxme_register_read(BMA2x2_X_AXIS_LSB_ADDR, xaxis_buf[0], 1) &amp;amp; bmxme_register_read(BMA2x2_X_AXIS_MSB_ADDR, xaxis_buf[1], 1) == true)
  {
    bmxme_register_read(BMA2x2_X_AXIS_LSB_ADDR, xaxis_buf[0], 1);
    bmxme_register_read(BMA2x2_X_AXIS_MSB_ADDR, xaxis_buf[1], 1);
    
    *pACC_X = (xaxis_buf[1] &amp;lt;&amp;lt; 8) | xaxis_buf[0];
    if(*pACC_X &amp;amp; 0x8000) *pACC_X-=65536;
    ret = true;
    }

  if(bmxme_register_read(BMA2x2_Y_AXIS_LSB_ADDR, yaxis_buf[0], 1) &amp;amp; bmxme_register_read(BMA2x2_Y_AXIS_MSB_ADDR, yaxis_buf[1], 1) == true)
  {
    bmxme_register_read(BMA2x2_Y_AXIS_LSB_ADDR, yaxis_buf[0], 1);
    bmxme_register_read(BMA2x2_Y_AXIS_MSB_ADDR, yaxis_buf[1], 1);

    *pACC_Y= (yaxis_buf[1] &amp;lt;&amp;lt; 8) | yaxis_buf[0];
    if(*pACC_Y &amp;amp; 0x8000) *pACC_Y-=65536;
    ret = true;
    }

  if(bmxme_register_read(BMA2x2_Z_AXIS_LSB_ADDR, zaxis_buf[0], 1) &amp;amp; bmxme_register_read(BMA2x2_Z_AXIS_MSB_ADDR, zaxis_buf[1], 1) == true)
  {
    bmxme_register_read(BMA2x2_Z_AXIS_LSB_ADDR, zaxis_buf[0], 1);
    bmxme_register_read(BMA2x2_Z_AXIS_MSB_ADDR, zaxis_buf[1], 1);

    *pACC_Z= (zaxis_buf[1] &amp;lt;&amp;lt; 8) | zaxis_buf[0];
    if(*pACC_Z &amp;amp; 0x8000) *pACC_Z-=65536;
 		
    ret = true;
    }
  
  return ret;
}



&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;and below is my main.c :&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;
#include &amp;lt;stdio.h&amp;gt;
#include &amp;quot;boards.h&amp;quot;
#include &amp;quot;app_util_platform.h&amp;quot;
#include &amp;quot;app_error.h&amp;quot;
#include &amp;quot;nrf_drv_twi.h&amp;quot;
#include &amp;quot;bma2x2.h&amp;quot;


#include &amp;quot;nrf_log.h&amp;quot;
#include &amp;quot;nrf_log_ctrl.h&amp;quot;
#include &amp;quot;nrf_log_default_backends.h&amp;quot;



int main(void)
{   
// initialize the logger
    APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
    NRF_LOG_DEFAULT_BACKENDS_INIT();

      NRF_LOG_INFO(&amp;quot;TWI accelerometer reading started.&amp;quot;);
      
	
	
// create arrays which will hold x,y &amp;amp; z co-ordinates values of acc
    static int16_t AccValue[3];

    bsp_board_init(BSP_INIT_LEDS | BSP_INIT_BUTTONS); // initialize the leds and buttons

    twi_master_init(); // initialize the twi 
    nrf_delay_ms(1000); // give some delay
    bmxme_init();
    
    while(bmxme_init() == false) // wait until bm055 sensor is successfully initialized
    {
      NRF_LOG_INFO(&amp;quot;BMX_055 initialization failed!!!&amp;quot;); // if it failed to initialize then print a message
      nrf_delay_ms(1000);
    }

   NRF_LOG_INFO(&amp;quot;BMX055 Initialization Successful!!!&amp;quot;); 

   NRF_LOG_INFO(&amp;quot;Reading Values from ACC&amp;quot;); // display a message to let the user know that the device is starting to read the values
   nrf_delay_ms(2000);


  
    
    while (true)
    {
        if(bmxme_ReadAcc(&amp;amp;AccValue[0], &amp;amp;AccValue[1], &amp;amp;AccValue[2]) == true) // Read acc value from bmx055 internal registers and save them in the array
        {
          NRF_LOG_INFO(&amp;quot;ACC Values:  x = %d  y = %d  z = %d&amp;quot;, AccValue[0], AccValue[1], AccValue[2]); // display the read values
        }
        else
        {
          NRF_LOG_INFO(&amp;quot;Reading ACC values Failed!!!&amp;quot;); // if reading was unsuccessful then let the user know about it
        }


       nrf_delay_ms(100); // give some delay 


    }
}

/** @} */
 &lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Getting x,y,z values from BMX055 using i2C</title><link>https://devzone.nordicsemi.com/thread/288928?ContentTypeID=1</link><pubDate>Wed, 13 Jan 2021 13:20:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9c8867b2-15c6-4670-b3bf-bb91e9bdbded</guid><dc:creator>awneil</dc:creator><description>&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/2783._5F00_Insert-Code-_2D00_-Nordic-2.png" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>