Hi all,
I have just some issues with sd_flash_write and sd_flash_page_erase functions. I have created some code to read the temperature value and save this value in memory, but I am not able to read it properly. I tested my app printing the messages before memory-related functions, but I am still not able to read the same value as in the temperature function. Can you maybe tell me in which part I made a mistake, and also why my temp sensor constantly reads 52 degrees instead of the normal room temperature value?? Did I maybe there also write some incorrect code? Thanks in advance!
Best regards,
Adnan.
Code:
#include <stdint.h>
#include <string.h>
/* HAL */
#include "boards.h"
#include "simple_hal.h"
#include "app_timer.h"
/* Core */
#include "nrf_mesh_config_core.h"
#include "nrf_mesh_gatt.h"
#include "nrf_mesh_configure.h"
#include "nrf_mesh.h"
#include "mesh_stack.h"
#include "device_state_manager.h"
#include "access_config.h"
#include "proxy.h"
/* Provisioning and configuration */
#include "mesh_provisionee.h"
#include "mesh_app_utils.h"
/* Models */
#include "generic_onoff_server.h"
/* Logging and RTT */
#include "log.h"
#include "rtt_input.h"
/* Example specific includes */
#include "app_config.h"
#include "example_common.h"
#include "nrf_mesh_config_examples.h"
#include "light_switch_example_common.h"
#include "app_onoff.h"
#include "ble_softdevice_support.h"
static void initilize(void)
{
__LOG_INIT(LOG_SRC_APP | LOG_SRC_ACCESS, LOG_LEVEL_INFO, LOG_CALLBACK_DEFAULT);
}
static uint32_t temp_read()
{
//int32_t raw_temp;
uint32_t temp;
sd_temp_get(&temp);
//uint32_t temperature = temp;
uint32_t temperature = temp;
//sd_temp_get(&raw_temp);
//int8_t temp = raw_temp >> 4; // divide by 4
__LOG(LOG_SRC_APP,LOG_LEVEL_INFO,"temp_read = %d \n",temperature);
return temperature;
}
static int32_t f_store(uint32_t temperature)
{
__LOG(LOG_SRC_APP,LOG_LEVEL_INFO,"I enter into f_store function!\n");
//uint32_t pg_size = NRF_FICR->CODEPAGESIZE;
//uint32_t pg_num = NRF_FICR->CODESIZE-2;
uint32_t f_addr = 0x0007f000;
//uint32_t *addr = (uint32_t *)(pg_size * pg_num);
uint32_t *addr = (uint32_t *)f_addr;
uint32_t tempa[1] = {temperature};
//uint32_t f_addr = 0x0007f000;
//uint32_t *p_addr = (uint32_t *)f_addr;
//sd_flash_page_erase(f_addr);
sd_flash_page_erase(f_addr);
//sd_flash_write(p_addr, tempa, 1);
sd_flash_write((uint32_t*)addr, (uint32_t*)tempa, 1);
__LOG(LOG_SRC_APP,LOG_LEVEL_INFO,"temp_read = %d \n", (uint32_t*)addr);
}
int main(void)
{
initilize();
__LOG(LOG_SRC_APP,LOG_LEVEL_INFO,"Hello!\n");
__LOG(LOG_SRC_APP,LOG_LEVEL_INFO,"Before temp_read function!\n");
temp_read();
__LOG(LOG_SRC_APP,LOG_LEVEL_INFO,"After temp_read function!\n");
f_store(temp_read());
__LOG(LOG_SRC_APP,LOG_LEVEL_INFO,"After f_store function!\n");
//initialize();
//(void) proxy_stop();
//start();
for (;;)
{
(void)sd_app_evt_wait();
}
}
Output in J-Link RTT Viewer:
