<?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>how to write the parameter of address</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/45283/how-to-write-the-parameter-of-address</link><description>hi,...... i am merging the nRF52832 and heart rate sensor BH1790, SEGGER 15.2V i want to read the heart rate sensor , for that i want to write the paramater of address, 41h 42h ... how to write , which function i have to use......</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 29 Mar 2019 01:26:35 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/45283/how-to-write-the-parameter-of-address" /><item><title>RE: how to write the parameter of address</title><link>https://devzone.nordicsemi.com/thread/179085?ContentTypeID=1</link><pubDate>Fri, 29 Mar 2019 01:26:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5aef3aba-e96a-4875-ba53-e3a8fa13440e</guid><dc:creator>takurx</dc:creator><description>&lt;p&gt;Hi, I just have merged the nRF52832 and heart rate sensor BH1792GLC.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/takurx/BH1792GLC-nRF52832-Example"&gt;https://github.com/takurx/BH1792GLC-nRF52832-Example&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;It&amp;#39;s better use example of twi-sensor.&lt;/p&gt;
&lt;p&gt;You want to set_data_to/get_data_from register(41h, 42h, ...) of slave address.&lt;/p&gt;
&lt;p&gt;&lt;span class="pl-c1"&gt;It can solve nRF SDK&amp;#39;s function of nrf_drv_twi_tx&lt;/span&gt;/&lt;span class="pl-c1"&gt;nrf_drv_twi_rx.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class="pl-c1"&gt;One point, &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class="pl-c1"&gt;TWI write only use nrf_drv_twi_tx,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class="pl-c1"&gt;But TWI read need to use both nrf_drv_twi_tx and nrf_drv_twi_rx. Thanks.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class="pl-c1"&gt;&lt;a href="https://github.com/takurx/BH1792GLC-nRF52832-Example/blob/master/examples/peripheral/twi_sensor/main.c"&gt;https://github.com/takurx/BH1792GLC-nRF52832-Example/blob/master/examples/peripheral/twi_sensor/main.c&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class="pl-c1"&gt;&lt;pre class="ui-code" data-mode="text"&gt;// Note:  I2C access should be completed within 0.5ms
int32_t i2c_write(uint8_t slv_adr, uint8_t reg_adr, uint8_t *reg, uint8_t reg_size)
{
    ret_code_t err_code;

    /*
    // m_bh1792.prm.msr      = BH1792_PRM_MSR_SINGLE, none
    if (m_bh1792.prm.msr &amp;lt;= BH1792_PRM_MSR_1024HZ) {
      if((slv_adr != BH1792_SLAVE_ADDR) || (reg_adr != BH1792_ADDR_MEAS_SYNC)) {
        while(FlexiTimer2::count == 1999);
      }
    }
    */

    uint32_t timeout = BH1792_TWI_TIMEOUT;

    twi_tx_buffer[0] = reg_adr;
    memcpy(&amp;amp;twi_tx_buffer[1], &amp;amp;reg[0], reg_size);
    
    err_code = nrf_drv_twi_tx(&amp;amp;m_twi, slv_adr, &amp;amp;twi_tx_buffer[0], reg_size + 1, false);
    if(err_code != NRF_SUCCESS) return err_code;
    while((!twi_tx_done) &amp;amp;&amp;amp; --timeout) ;
    if(!timeout) return NRF_ERROR_TIMEOUT;
    twi_tx_done = false;

    //return rc;   //rc is return value that arduino, Wire endTransmission, rc:0 is normal
    return 0;
}


// Note:  I2C access should be completed within 0.5ms
int32_t i2c_read(uint8_t slv_adr, uint8_t reg_adr, uint8_t *reg, uint8_t reg_size)
{
    ret_code_t err_code;

    /*
    // m_bh1792.prm.msr      = BH1792_PRM_MSR_SINGLE, none
    if (m_bh1792.prm.msr &amp;lt;= BH1792_PRM_MSR_1024HZ) {
      while(FlexiTimer2::count == 1999);
    }
    */

    uint32_t timeout = BH1792_TWI_TIMEOUT;

    err_code = nrf_drv_twi_tx(&amp;amp;m_twi, slv_adr, &amp;amp;reg_adr, 1, false);
    if(err_code != NRF_SUCCESS) return err_code;

    while((!twi_tx_done) &amp;amp;&amp;amp; --timeout);
    if(!timeout) return NRF_ERROR_TIMEOUT;
    twi_tx_done = false;

    err_code = nrf_drv_twi_rx(&amp;amp;m_twi, slv_adr, reg, reg_size);
    if(err_code != NRF_SUCCESS) return err_code;

    timeout = BH1792_TWI_TIMEOUT;
    while((!twi_rx_done) &amp;amp;&amp;amp; --timeout);
    if(!timeout) return NRF_ERROR_TIMEOUT;
    twi_rx_done = false;

    //return rc;  //rc:0 is normal, rc:4 is error. but in nrf5 when case of error, already return
    return 0;
}&lt;/pre&gt;&lt;/span&gt;&lt;span class="pl-c1"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class="pl-c1"&gt;I also will try BH1790GLC. It have to exist heart rate(BPM, Upper one is only measured raw data) example.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class="pl-c1"&gt;BH1790GLC_HeartRate.zip - &lt;a href="http://micro.rohm.com/en/download_support/sensor_module/kiyaku.php?file=data/software/BH1790GLC_HeartRate.zip" rel="nofollow"&gt;http://micro.rohm.com/en/download_support/sensor_module/kiyaku.php?file=data/software/BH1790GLC_HeartRate.zip&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to write the parameter of address</title><link>https://devzone.nordicsemi.com/thread/177947?ContentTypeID=1</link><pubDate>Sat, 23 Mar 2019 16:20:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f611a0ce-7aab-4a02-a41f-29704eaa9945</guid><dc:creator>awneil</dc:creator><description>[quote userid="74848" url="~/f/nordic-q-a/45283/how-to-write-the-parameter-of-address"]write the paramater of address, 41h 42h [/quote]
&lt;p&gt;I don&amp;#39;t understand what you mean by that - please clarify&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>