<?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 combine nrf5 SDK code with mesh sdk?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/69199/how-to-combine-nrf5-sdk-code-with-mesh-sdk</link><description>Hi guys, 
 I have already created some code in a peripheral folder inside nrf5 SDK documentation related to temperature readings and the way how to save the data in the flash memory and read it after that in order for example to calculate the average</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 08 Jan 2021 14:38:27 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/69199/how-to-combine-nrf5-sdk-code-with-mesh-sdk" /><item><title>RE: How to combine nrf5 SDK code with mesh sdk?</title><link>https://devzone.nordicsemi.com/thread/288208?ContentTypeID=1</link><pubDate>Fri, 08 Jan 2021 14:38:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:37720670-1286-4e83-8673-579ca54cb3da</guid><dc:creator>tesc</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Regarding the issues with temperature reading and printing floats, it looks like you already did get help and good suggestions in other threads before the holidays.&lt;/p&gt;
&lt;p&gt;As a general remark, I see in your code that you do quite some writing and erasing of flash, instead of simply holding things in RAM. If you get one read/erase cycle on the flash page every 5 seconds, then you may risk the flash starting to fail after 10000 * 5 = 50000 seconds, or after around fourteen hours of operation, ref. the &lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.nrf52832.ps.v1.1%2Fabs_max_ratings.html&amp;amp;anchor=abs_max_ratings"&gt;absolute maximum ratings table&lt;/a&gt; of the nRF52832 Product Specification. (It may of course last longer, but 10000 is the minimum rating that we guarantee.)&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Terje&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to combine nrf5 SDK code with mesh sdk?</title><link>https://devzone.nordicsemi.com/thread/285711?ContentTypeID=1</link><pubDate>Thu, 17 Dec 2020 18:17:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a6c874c6-3ae8-4580-910e-67731f5033d8</guid><dc:creator>Aduka_27</dc:creator><description>&lt;p&gt;Hi Terje,&lt;/p&gt;
&lt;p&gt;First of all, thanks a lot for this very detailed explanation of my problem. I have already moved to SoftDevice APIs and for now, I created the same application as I sent you before. But also, in this example, I have some problems as I am not able to read the temperature properly, and also if you can check if everything is correct. I have already flashed my board and run the code, and everything works as I expected, but it&amp;#39;s always better if somebody else with more experience checks the code again. Also, I have a problem with printing the float values, I tried to use NRF_LOG but without success (because in the previous example I used NRF_LOG_FLOAT_MARKER)?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Adnan.&lt;/p&gt;
&lt;p&gt;Here is the code:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#include &amp;lt;stdint.h&amp;gt;
#include &amp;lt;string.h&amp;gt;

/* HAL */
#include &amp;quot;boards.h&amp;quot;
#include &amp;quot;simple_hal.h&amp;quot;
#include &amp;quot;app_timer.h&amp;quot;

/* Core */
#include &amp;quot;nrf_mesh_config_core.h&amp;quot;
#include &amp;quot;nrf_mesh_gatt.h&amp;quot;
#include &amp;quot;nrf_mesh_configure.h&amp;quot;
#include &amp;quot;nrf_mesh.h&amp;quot;
#include &amp;quot;mesh_stack.h&amp;quot;
#include &amp;quot;device_state_manager.h&amp;quot;
#include &amp;quot;access_config.h&amp;quot;
#include &amp;quot;proxy.h&amp;quot;

/* Provisioning and configuration */
#include &amp;quot;mesh_provisionee.h&amp;quot;
#include &amp;quot;mesh_app_utils.h&amp;quot;

/* Models */
#include &amp;quot;generic_onoff_server.h&amp;quot;

/* Logging and RTT */
#include &amp;quot;log.h&amp;quot;
#include &amp;quot;rtt_input.h&amp;quot;

/* Example specific includes */
#include &amp;quot;app_config.h&amp;quot;
#include &amp;quot;example_common.h&amp;quot;
#include &amp;quot;nrf_mesh_config_examples.h&amp;quot;
#include &amp;quot;light_switch_example_common.h&amp;quot;
#include &amp;quot;app_onoff.h&amp;quot;
#include &amp;quot;ble_softdevice_support.h&amp;quot;

#include &amp;quot;nrf_delay.h&amp;quot;
#include &amp;quot;nrf_sdh.h&amp;quot;
#include &amp;quot;nrf_sdh_soc.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;

static void initilize(void)
{

    __LOG_INIT(LOG_SRC_APP | LOG_SRC_ACCESS, LOG_LEVEL_INFO, LOG_CALLBACK_DEFAULT);

}

static int32_t f_temp()
{

    int32_t temp;

    (void)sd_temp_get(&amp;amp;temp);

    int32_t temperature = (int8_t)(temp);

    __LOG(LOG_SRC_APP,LOG_LEVEL_INFO,&amp;quot;temp_read = %d \n&amp;quot;,temperature);	

    return temperature;

}

static int32_t f_store(int32_t temperature, uint32_t *i, int temp_size)
{

    int32_t tempa = temperature;

    uint32_t pg_size = NRF_FICR-&amp;gt;CODEPAGESIZE;
    uint32_t pg_num = NRF_FICR-&amp;gt;CODESIZE-2; 

    uint32_t *addr_store = (uint32_t *)(pg_size * pg_num);

    int32_t tempa_array[*i+1];

    for (int k=0; k&amp;lt;=*i; k++){
        
        tempa_array[k] = *(addr_store+k);  
    }

    tempa_array[*i] = tempa;

    sd_flash_page_erase(pg_num);

    sd_flash_write((uint32_t*)addr_store, (int32_t*)tempa_array, *i+1);

    for (int j=0; j&amp;lt;=*i; j++){
    
        __LOG(LOG_SRC_APP,LOG_LEVEL_INFO,&amp;quot;Temperature value is: %d \n&amp;quot;, *(uint32_t*)(addr_store+j));	   
    }    
}

static int32_t f_compute(int temp_size){

    uint32_t pg_size = NRF_FICR-&amp;gt;CODEPAGESIZE;
    uint32_t pg_num = NRF_FICR-&amp;gt;CODESIZE-2; 

    uint32_t *addr_store = (uint32_t *)(pg_size * pg_num);

    uint32_t pg_size_compute = NRF_FICR-&amp;gt;CODEPAGESIZE;
    uint32_t pg_num_compute = NRF_FICR-&amp;gt;CODESIZE-3;

    uint32_t *addr_compute = (uint32_t *)(pg_size_compute * pg_num_compute);

    int temp_sum = 0;

    for (int k = 0; k&amp;lt;temp_size; k++){
 
        temp_sum = temp_sum + (*(addr_store+k));
    }

    int average_temp[1] = {temp_sum / temp_size};

    sd_flash_page_erase(pg_num_compute);
    sd_flash_write((uint32_t*)addr_compute, (uint32_t*)average_temp, 1);

    __LOG(LOG_SRC_APP,LOG_LEVEL_INFO,&amp;quot;Average temperature is: %d \n&amp;quot;, *(uint32_t*)(addr_compute));

    sd_flash_page_erase(pg_num);

}

int main(void)
{

    initilize();

    int temp_size = 3;

    uint32_t pg_size_pointer = NRF_FICR-&amp;gt;CODEPAGESIZE;
    uint32_t pg_num_pointer = NRF_FICR-&amp;gt;CODESIZE-4; // use last page in flash 

    uint32_t *addr_pointer = (uint32_t *)(pg_size_pointer * pg_num_pointer);

    __LOG(LOG_SRC_APP,LOG_LEVEL_INFO,&amp;quot;Pointer value is = %d \n&amp;quot;, *(uint32_t*)(addr_pointer));

    if (*(uint32_t*)(addr_pointer) == -1){

        __LOG(LOG_SRC_APP,LOG_LEVEL_INFO,&amp;quot;Pointer je -1!\n&amp;quot;);

        uint32_t pointer_array[1] = {0};
    
        sd_flash_write((uint32_t*)addr_pointer, (uint32_t*)pointer_array, 1);

        __LOG(LOG_SRC_APP,LOG_LEVEL_INFO,&amp;quot;Pointer value is = %d \n&amp;quot;, *(uint32_t*)(addr_pointer));

    }

    while(true) {


        if (*(uint32_t*)(addr_pointer) &amp;lt; temp_size){
        
            __LOG(LOG_SRC_APP,LOG_LEVEL_INFO,&amp;quot;Usao sam u if funkciju!\n&amp;quot;);
            f_temp();
            f_store(f_temp(), addr_pointer, temp_size);
            uint32_t new_i[1] = {*(addr_pointer) + 1};
            sd_flash_page_erase(pg_num_pointer);
            sd_flash_write((uint32_t*)addr_pointer, (uint32_t*)new_i, 1);
            __LOG(LOG_SRC_APP,LOG_LEVEL_INFO,&amp;quot;Pointer value is = %d \n&amp;quot;, *(uint32_t*)(addr_pointer)); 
        }

        else{
        
             f_compute(temp_size);
             sd_flash_page_erase(pg_num_pointer);
             uint32_t new_i[1] = {0};
             sd_flash_write((uint32_t*)addr_pointer, (uint32_t*)new_i, 1);
        }

        nrf_delay_ms(10000);

        }

}
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to combine nrf5 SDK code with mesh sdk?</title><link>https://devzone.nordicsemi.com/thread/285697?ContentTypeID=1</link><pubDate>Thu, 17 Dec 2020 16:24:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ebeddb1e-6e01-408b-a005-1a5c497e1d31</guid><dc:creator>tesc</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;With Bluetooth mesh (as with BLE) you are using the SoftDevice (our BLE stack), which takes control of many of the peripherals on the SoC, including control of the non-volatile memory controller (nvmc). Therefore you need to use the SoftDevice API for accessing certain peripherals (including nvmc).&lt;/p&gt;
&lt;p&gt;That means that the code that you provided will not work with the SoftDevice (and therefore not with any BLE or Bluetooth mesh applications either.)&lt;/p&gt;
&lt;p&gt;A couple of our flash examples come in both &amp;quot;blank&amp;quot; versions and &amp;quot;s132&amp;quot; versions (for the S132 SoftDevice). Those are the &lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fsdk_nrf5_v17.0.2%2Ffstorage_example.html"&gt;Flash Storage Example&lt;/a&gt; and the &lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fsdk_nrf5_v17.0.2%2Ffds_example.html"&gt;Flash Data Storage Example&lt;/a&gt;. They both use higher abstractions for storing to flash.&lt;/p&gt;
&lt;p&gt;For more information on what peripherals are needed by the SoftDevice, have a look at the &lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fsds_s132%2FSDS%2Fs1xx%2Fsd_resource_reqs%2Fhw_block_interrupt_vector.html"&gt;Hardware peripherals&lt;/a&gt; section of the SoftDevice Specification.&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Terje&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to combine nrf5 SDK code with mesh sdk?</title><link>https://devzone.nordicsemi.com/thread/284121?ContentTypeID=1</link><pubDate>Wed, 09 Dec 2020 14:42:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fed626a7-b767-469d-a2be-ce23aaf0a052</guid><dc:creator>Aduka_27</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Yes, my current code is completely based on nRF5 SDK for which I used the existing code in the peripherals folder. Now, I want to use that code in order to send the average temp value to let&amp;#39;s say server, but using the BLE mesh. I tried to copy and paste my code, together with all needed drivers and libraries to the existing BLE mesh example but without success. In the attachment, I send you my current code if you want just to check if we understand each other correctly. Thanks in advance!&lt;/p&gt;
&lt;p&gt;Best regards,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Adnan.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;pre class="ui-code" data-mode="text"&gt;#include &amp;lt;stdbool.h&amp;gt;
#include &amp;lt;stdint.h&amp;gt;
#include &amp;lt;stdio.h&amp;gt;
#include &amp;quot;nrf.h&amp;quot;
#include &amp;quot;nrf_drv_saadc.h&amp;quot;
#include &amp;quot;nrf_drv_ppi.h&amp;quot;
#include &amp;quot;nrf_drv_timer.h&amp;quot;
#include &amp;quot;boards.h&amp;quot;
#include &amp;quot;nrf_delay.h&amp;quot;
#include &amp;quot;nrf_temp.h&amp;quot;
#include &amp;quot;app_error.h&amp;quot;
#include &amp;quot;bsp.h&amp;quot;
#include &amp;quot;app_util_platform.h&amp;quot;
#include &amp;quot;nrf_pwr_mgmt.h&amp;quot;
#include &amp;quot;nrf_nvmc.h&amp;quot;
#include &amp;quot;nordic_common.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;

#include &amp;quot;app_timer.h&amp;quot;
#include &amp;quot;nrf_drv_clock.h&amp;quot;

#include &amp;quot;nrf_cli.h&amp;quot;
#include &amp;quot;nrf_cli_uart.h&amp;quot;

void saadc_callback_handler (nrf_drv_saadc_evt_t const * p_event){

  // Empty handler function
}

void saadc_init(void){

  ret_code_t err_code;

  // Create a config struct and assign it default values along with the pin number for ADC input
  // Configure the input as Single Ended (One Pin Reading)

  nrf_saadc_channel_config_t channel_config = NRFX_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_VDD);

  // Initilize the saadc
  err_code = nrf_drv_saadc_init(NULL, saadc_callback_handler);
  APP_ERROR_CHECK(err_code);

  // Initilize the channel which will be connected to that specific pin
  err_code = nrfx_saadc_channel_init(0, &amp;amp;channel_config);
  APP_ERROR_CHECK(err_code);

}

float f_temp(){


    float temp; 

    NRF_TEMP-&amp;gt;TASKS_START = 1;

    while (NRF_TEMP-&amp;gt;EVENTS_DATARDY == 0)
    {
        // Do nothing.
    }
    
    NRF_TEMP-&amp;gt;EVENTS_DATARDY = 0;

    temp = (nrf_temp_read() / 4);

    NRF_TEMP-&amp;gt;TASKS_STOP = 1;

    return temp;

}

float f_store(float temp, uint32_t *i, int temp_size){


    uint32_t tmp_temp = temp;

    uint32_t f_addr = 0x0007f000;

    uint32_t * p_addr = (uint32_t *)f_addr;

    uint32_t tmp_temp_array[*i+1];

    for (int k = 0; k&amp;lt;=*i; k++) {
      
      tmp_temp_array[k] = *(p_addr+k);
      
    }

    tmp_temp_array[*i] = tmp_temp;

    nrf_nvmc_page_erase(f_addr);
    nrf_nvmc_write_words(f_addr, tmp_temp_array, *i+1);
    
   
    for (int j = 0; j&amp;lt;=*i; j++){
      NRF_LOG_INFO(&amp;quot;i memory is: &amp;quot; NRF_LOG_FLOAT_MARKER &amp;quot; \n&amp;quot;, NRF_LOG_FLOAT(*i));
      NRF_LOG_INFO(&amp;quot;j is: &amp;quot; NRF_LOG_FLOAT_MARKER &amp;quot; \n&amp;quot;, NRF_LOG_FLOAT(j));
      NRF_LOG_INFO(&amp;quot;In memory data is: &amp;quot; NRF_LOG_FLOAT_MARKER &amp;quot; \n&amp;quot;, NRF_LOG_FLOAT(*(p_addr+j)));
    }

    NRF_LOG_INFO(&amp;quot;i at end of f_store is: &amp;quot; NRF_LOG_FLOAT_MARKER &amp;quot; \n&amp;quot;, NRF_LOG_FLOAT(*i));

}

float f_compute(int temp_size){

  uint32_t f_addr = 0x0007f000;

  uint32_t * p_addr = (uint32_t *)f_addr;

  uint32_t avg_addr = 0x0007d000;

  uint32_t * avg_pointer = (uint32_t *)avg_addr;

  float temp_sum = 0;

  for (int k = 0; k&amp;lt;temp_size; k++){
 
    temp_sum = temp_sum + (*(p_addr+k));
  }

  float average_temp = temp_sum / temp_size;

  NRF_LOG_INFO(&amp;quot;Average temperature is: &amp;quot; NRF_LOG_FLOAT_MARKER &amp;quot; \n&amp;quot;, NRF_LOG_FLOAT(average_temp));

  nrf_nvmc_page_erase(avg_addr);
  nrf_nvmc_write_word(avg_addr, average_temp);

  nrf_nvmc_page_erase(f_addr);
}

int main(void)
{
    saadc_init();

    nrf_saadc_value_t adc_val;


    nrf_temp_init();
    APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
    NRF_LOG_DEFAULT_BACKENDS_INIT();
    
    int temp_size = 10;

    uint32_t i_addr = 0x0007e000;
    uint32_t * i_pointer = (uint32_t *)i_addr;

    NRF_LOG_INFO(&amp;quot;Test is: &amp;quot; NRF_LOG_FLOAT_MARKER &amp;quot; \n&amp;quot;, NRF_LOG_FLOAT(*i_pointer));

    if (*i_pointer == -1){
      nrf_nvmc_write_word(i_addr, 0);
    }
    
    NRF_LOG_INFO(&amp;quot;agfter Test is: &amp;quot; NRF_LOG_FLOAT_MARKER &amp;quot; \n&amp;quot;, NRF_LOG_FLOAT(*i_pointer));

    while (true)
    {
        

        nrfx_saadc_sample_convert(0, &amp;amp;adc_val);

        float voltage = adc_val * 3.6 / 1024;

        NRF_LOG_INFO(&amp;quot;Volts: &amp;quot; NRF_LOG_FLOAT_MARKER &amp;quot; \n&amp;quot;, NRF_LOG_FLOAT(voltage));

        //NRF_LOG_INFO(&amp;quot;Hello!\n&amp;quot;);

        if (voltage &amp;gt; 2.5){
          
          NRF_LOG_INFO(&amp;quot;i: &amp;quot; NRF_LOG_FLOAT_MARKER &amp;quot; \n&amp;quot;, NRF_LOG_FLOAT(*i_pointer));

          if (*i_pointer &amp;lt; temp_size){
            NRF_LOG_INFO(&amp;quot;uso u if\n&amp;quot;);
            
            f_store(f_temp(), i_pointer, temp_size);
            const uint32_t new_i = *(i_pointer) + 1;
            NRF_LOG_INFO(&amp;quot;i after f-store() is: &amp;quot; NRF_LOG_FLOAT_MARKER &amp;quot; \n&amp;quot;, NRF_LOG_FLOAT(new_i));
            nrf_nvmc_page_erase(i_addr);
            nrf_nvmc_write_word(i_addr, new_i);
            NRF_LOG_INFO(&amp;quot;after new i: &amp;quot; NRF_LOG_FLOAT_MARKER &amp;quot; \n&amp;quot;, NRF_LOG_FLOAT(*i_pointer));
            //nrf_nvmc_write_word(i_addr, 2);
            //NRF_LOG_INFO(&amp;quot;after second new i: &amp;quot; NRF_LOG_FLOAT_MARKER &amp;quot; \n&amp;quot;, NRF_LOG_FLOAT(*i_pointer));
          } else {
            NRF_LOG_INFO(&amp;quot;uso u else\n&amp;quot;);
            f_compute(temp_size); //in this function, erase from memory
            //i = 0;
            nrf_nvmc_page_erase(i_addr);
            nrf_nvmc_write_word(i_addr, 0);
          }


        }
        else{
        
          NRF_LOG_INFO(&amp;quot;Not possible!\n&amp;quot;);
        }

        nrf_delay_ms(5000);

        NRF_LOG_FLUSH();
    }
}



&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to combine nrf5 SDK code with mesh sdk?</title><link>https://devzone.nordicsemi.com/thread/284114?ContentTypeID=1</link><pubDate>Wed, 09 Dec 2020 14:36:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:57a0c2b2-b52d-469a-a0bf-53454b5b0478</guid><dc:creator>tesc</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;From what I understand you have a project based on the nRF5 SDK, where you store temperature readings to flash, before you read them out and do some calculation. Now you want to use Bluetooth mesh for communicating the result of the calculation to other devices.&lt;/p&gt;
&lt;p&gt;If you are only going to use Bluetooth mesh in your project, and not &amp;quot;normal&amp;quot; BLE, then I think it is best to start with an example from the nRF5 SDK for Mesh, and add your code to that project. Otherwise you can have a look at &lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.meshsdk.v5.0.0%2Fmd_doc_user_guide_integrating_mesh_nrf5_sdk.html"&gt;Integrating Bluetooth mesh into nRF5 SDK examples&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Please note that depending on your use case, writing the temperature readings to flash in order to store them is not necessarily a good idea. If the time span that you need to temporarily store the values is short, then keeping them in RAM (until you have enough values to do the calculation) may be a better idea. The flash of the nRF52 series is typically guaranteeing only 10k write/erase cycles before you may start seeing bit errors, while RAM does not have such a constraint.&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Terje&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>