<?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>pstorage and app_timer</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/14653/pstorage-and-app_timer</link><description>Hi, 
 I would like to know what is wrong with my code, which is presened below. Each time the timer is triggered I would like that the program writes four bytes into the flash. As you can see I used the pstorage methods for writing into the flash. When</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 22 Jun 2016 13:52:49 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/14653/pstorage-and-app_timer" /><item><title>RE: pstorage and app_timer</title><link>https://devzone.nordicsemi.com/thread/55920?ContentTypeID=1</link><pubDate>Wed, 22 Jun 2016 13:52:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:16677d9a-41aa-4fd4-aa76-59c671cbc180</guid><dc:creator>John</dc:creator><description>&lt;p&gt;Thats great. Glad you got it working. Can you mark the answer as accepted?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: pstorage and app_timer</title><link>https://devzone.nordicsemi.com/thread/55919?ContentTypeID=1</link><pubDate>Wed, 22 Jun 2016 07:14:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:22b31a99-dcdf-4b52-8958-949e68df13a3</guid><dc:creator>samo</dc:creator><description>&lt;p&gt;According to recommendation from John DeWitt side I used scheduler for writing in flash. Here is my code which work fine. Thanks for help John DeWitt and Dave_couling.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;void experimental_scheduler_event_handler(void *p_event_data, uint16_t event_size)
{
	uint8_t err_code;
	uint8_t dest_data_0[4];	
	  
	uint32_t err_codee;
	
	uint8_t      source_data[4] = {0x25, 0x00, 0x00, 0x00};		 
		
	pstorage_wait_handle = block_0_handle.block_id;            //Specify which pstorage handle to wait for
	pstorage_wait_flag = 1; 	
		
	err_codee=pstorage_update(&amp;amp;block_0_handle, source_data,4,0);     //Write to flash, only one block is allowed for each pstorage_store command
	if(err_codee != NRF_SUCCESS)
	{
			
	}		
	
	while(pstorage_wait_flag)
	{

		 power_manage();
		
	}
	

	pstorage_load(dest_data_0, &amp;amp;block_0_handle, 4, 0);	    

	printf(&amp;quot;value %d\n&amp;quot;, dest_data_0[0]);
	
		
}



static void experimental_timer_handler(void *p_context)
{
	// here I will put some other tasks
  app_sched_event_put(NULL, 0, experimental_scheduler_event_handler);	
}
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: pstorage and app_timer</title><link>https://devzone.nordicsemi.com/thread/55917?ContentTypeID=1</link><pubDate>Tue, 21 Jun 2016 21:19:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:939bc28e-74b8-47b5-b732-7eb0f6187764</guid><dc:creator>Dave_couling</dc:creator><description>&lt;p&gt;Try adding app_sched_execute(); into your while loop.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: pstorage and app_timer</title><link>https://devzone.nordicsemi.com/thread/55916?ContentTypeID=1</link><pubDate>Tue, 21 Jun 2016 21:09:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ba2cb405-1e55-4d5e-98e7-37a3ffa8f4e8</guid><dc:creator>samo</dc:creator><description>&lt;p&gt;The following declaration is used: `static volatile  uint8_t 							pstorage_wait_flag = 0, but I get the same problem.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: pstorage and app_timer</title><link>https://devzone.nordicsemi.com/thread/55918?ContentTypeID=1</link><pubDate>Tue, 21 Jun 2016 17:25:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8c74f92c-515a-4cad-b7a0-f8e28b663053</guid><dc:creator>John</dc:creator><description>&lt;p&gt;Your timer handler is probably executing in an interrupt context and blocking the call of your callback handler. Rather than waiting in the timer handler, either set a flag to trigger the wait loop in you main loop. Alternatively Nordic provides a scheduler as well that lets you trigger things in an interrupt that later get handled in your main context.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: pstorage and app_timer</title><link>https://devzone.nordicsemi.com/thread/55915?ContentTypeID=1</link><pubDate>Tue, 21 Jun 2016 17:19:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cb4080db-b53f-41aa-92bd-c76e540f17d9</guid><dc:creator>Dave_couling</dc:creator><description>&lt;p&gt;Did you declare pstorage_wait_flag as a volatile?   This is required when you have a loop variable which may be accessed from a different point in memory (ISR) to assure logically everything runs smoothly.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>