<?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>Global variables are not updated</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/44556/global-variables-are-not-updated</link><description>Hi, I have created a global variables header file that I use through out my project. The variables are static volatile and intialized to zero. 
 When I update them with a new value (i.e. a =150) and try to print them to serial console of Segger, in main</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 07 Mar 2019 15:35:29 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/44556/global-variables-are-not-updated" /><item><title>RE: Global variables are not updated</title><link>https://devzone.nordicsemi.com/thread/174860?ContentTypeID=1</link><pubDate>Thu, 07 Mar 2019 15:35:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7f2ba34a-b3d5-4785-a146-2ef64080979a</guid><dc:creator>masterLee</dc:creator><description>&lt;p&gt;No errors and no warnings are returned in segger. I use the same approach in MPLAB X IDE for PIC32 and values are updated with no problem..&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Global variables are not updated</title><link>https://devzone.nordicsemi.com/thread/174859?ContentTypeID=1</link><pubDate>Thu, 07 Mar 2019 15:34:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0f4519d0-2e57-4875-9bf3-725c633e893a</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;Since this is a .h file you are defining a unique instance of these variables for every time the header file is included. As they are &amp;quot;static&amp;quot; each of these instances is not visible to any other module, but each is visible withiin that c file which included the .h file; remove &amp;quot;static&amp;quot; and you will see a flood of errors about multiple definitions. So to use them as global variables place them in a single c or cpp file and delete the &amp;quot;static&amp;quot; prefix; also keep the variables in the .h file, but replace &amp;quot;static&amp;quot; with &amp;quot;extern&amp;quot; which tells each c file that these variables are indeed global.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Global variables are not updated</title><link>https://devzone.nordicsemi.com/thread/174854?ContentTypeID=1</link><pubDate>Thu, 07 Mar 2019 15:25:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8de8230b-d017-4d59-9fed-45b4ac5d1c96</guid><dc:creator>Andy</dc:creator><description>&lt;p&gt;I&amp;#39;m no absolute expert in C, but I&amp;#39;ve worked with it for years already and I&amp;#39;ve never seen something like this. Does it even compile? Do you have warnings?&lt;/p&gt;
&lt;p&gt;You should declare your variables in the header file and define them in the source file. You can&amp;#39;t have them static and want them to be public at the same time. Also declaring everything as volatile is bad practice.&lt;/p&gt;
&lt;p&gt;I&amp;#39;d advise you to read some C basics. There are tons of threads in stack overflow where you can start. For example:&amp;nbsp;&lt;a href="https://stackoverflow.com/questions/1164167/variable-declaration-in-a-header-file"&gt;stackoverflow.com/.../variable-declaration-in-a-header-file&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>