<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.arm.com/utility/feedstylesheets/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/"><channel><title>Problem in Interrupt</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/37158/problem-in-interrupt</link><description> 
I have a strange problem in interrupt, I am incrementing a
variable in interrupt and displayng in main program, the code is
working fine for some time , latter the system gets hanged , i dont
know why?? 

 
if there is any solution to this problem plz</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: Problem in Interrupt</title><link>https://community.arm.com/thread/112647?ContentTypeID=1</link><pubDate>Tue, 27 Feb 2007 19:22:29 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:bc845be6-b384-495c-a5e9-a099a12dc0af</guid><dc:creator>Jonny Doin</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;&amp;quot;found that this thread is already talking about the interrupt
problem in &lt;b&gt;Nordic nrf24e1&lt;/b&gt;&amp;quot;&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
The Nordic chip is never mentioned in this thread. You should
really open a new thread to discuss your problem. If not for
netiquette, to show others that your problem is not the old problem
already discussed in the thread.&lt;/p&gt;

&lt;p&gt;
One note regarding &lt;b&gt;using 0&lt;/b&gt;: when you declare a interrupt
function specifying &lt;b&gt;using N&lt;/b&gt;, the interrupt entry code assumes
that the declared bank is &amp;#39;set aside&amp;#39; for the interrupt, and does not
preserve any used registers. So, if you declare &lt;b&gt;using 0&lt;/b&gt; and
your program uses bank 0 for anything else, your interrupt will
overwrite main program registers, and if you&amp;#39;re lucky your program
will crash. If you&amp;#39;re out of luck, the program may actually run with
some weird side effect.&lt;/p&gt;

&lt;p&gt;
The &lt;b&gt;using&lt;/b&gt; directive should only be used for ISRs that are
at the same priority level, and that don&amp;#39;t call any functions that
are declared with other banked domains.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem in Interrupt</title><link>https://community.arm.com/thread/98931?ContentTypeID=1</link><pubDate>Tue, 27 Feb 2007 18:46:31 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:a67fcbd0-268c-4668-b71d-5fab1bc002ef</guid><dc:creator>Nikhil Deshpande</dc:creator><description>&lt;p&gt;&lt;p&gt;
Hello All,&lt;/p&gt;

&lt;p&gt;
A newbie to this forum, I was going through a lot of threads and
found that this thread is already talking about the interrupt problem
in Nordic nrf24e1. I am working with the same chip and having trouble
programming the interrupt. Here is the brief.&lt;br /&gt;
I am using the RTC to wake up from sleep. The program should vector
to the programmed interrupt and after exiting the interrupt should go
to the next instruction after the sleep (thats what it says in the
manual...) and output the value that I am changing in the interrupt.
It should keep doing this just to show that the interrupt works.&lt;/p&gt;

&lt;p&gt;
Here is the code:&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;
#pragma iv(0x0000) // Interrupt vector begins at 0&lt;br /&gt;
#pragma interval(8) // Interval for vector is 8&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;#include &amp;lt;Nordic\reg24e1.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;#define TICK 10e-3 // 10ms (100Hz) tick&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;unsigned char xdata a=0;&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;void WriteRTC(unsigned int w){&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;while(REGX_CTRL &amp;amp; 0x10) // Wait to be ready&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;;&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;REGX_MSB = w &amp;gt;&amp;gt; 8;&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;REGX_LSB = w &amp;amp; 0xff;&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;REGX_CTRL = 0x0a;&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;while(REGX_CTRL &amp;amp; 0x10) // Wait to be ready&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;;&lt;br /&gt;
}&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;void RTCINT (void) interrupt 12 using 0{&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;WDTI = 0; // reset RTC interrupt flag&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;a++;&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;}&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;void main(void){&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;EA = 1; // Enable Global Interrupt&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;EWDI = 1; // Enable RTC interrupt&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;PWDI = 1; // RTC Interrupt High priority&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;WriteRTC(1/TICK); // RTC Real time clock - 1 sec&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;while(1){&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;CK_CTRL = 0x01; // sleep&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;printf(&amp;quot;%d\n&amp;quot;,&amp;amp;a);&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;}&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;}&lt;br /&gt;&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
I have enabled global interrupts and only one other interrupt,
that is RTC. I am sure they are no other interrupt sources. I have
put in the &lt;b&gt;using&lt;/b&gt; operator as &amp;#39;0&amp;#39; since the default register
bank is &amp;#39;0&amp;#39;. So my interrupt function will also be in bank &amp;#39;0&amp;#39;. The
interrupt number is also correct according to the manuals.&lt;br /&gt;
I tried with the breakpoints but the program just does not vector to
the interrupt and increment &amp;#39;a&amp;#39;! I don&amp;#39;t know whether it is to do
with the &lt;b&gt;using&lt;/b&gt; or declaration or something else. Has anyone
done it before and any differently than I have?&lt;/p&gt;

&lt;p&gt;
Thanks in advance,&lt;/p&gt;

&lt;p&gt;
- Nikhil&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem in Interrupt</title><link>https://community.arm.com/thread/74815?ContentTypeID=1</link><pubDate>Tue, 13 Feb 2007 19:20:38 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:8eeb2608-a96e-4b8a-b3f9-d4adc381af6c</guid><dc:creator>Jonny Doin</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;&amp;quot;What do you suppose will happen to your program when
&lt;b&gt;main()&lt;/b&gt; exits...?&amp;quot;&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
Well that will depend on the manufacturer of the chip, of course.
If the chip is manufactured in the nordic countries, for example, the
processing will continue in the Valhalla, as long as it was a valiant
program.&lt;/p&gt;

&lt;p&gt;
If the fab is in the UK, it will continue in Valinor, but only if
its linker produced the necessary ELF files. If only DWARF files are
available, the processing will continue in Moria.&lt;/p&gt;

&lt;p&gt;
If it&amp;#39;s a Philips 8051 chip, it will probably continue
underwater.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem in Interrupt</title><link>https://community.arm.com/thread/98910?ContentTypeID=1</link><pubDate>Tue, 13 Feb 2007 10:07:54 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:d0a997a5-9b74-4d47-b7a4-39778ac7ca29</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;&amp;quot;He isn&amp;#39;t using the var as an array subscript or a pointer
offset,is he?&amp;quot;&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
Well, he hasn&amp;#39;t shown any code that does that - but then the code
that he has shown doesn&amp;#39;t make sense, does it?&lt;/p&gt;

&lt;p&gt;
Jonny was just proposing an example of one way that &lt;i&gt;could&lt;/i&gt;
lead to crashing the program&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem in Interrupt</title><link>https://community.arm.com/thread/88176?ContentTypeID=1</link><pubDate>Tue, 13 Feb 2007 08:49:04 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:d98fcd84-c5fa-4183-b3dc-0f2ec7718e0f</guid><dc:creator>erik  malund</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;What do you suppose will happen to your program when main()
exits...?&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
I guess that will happen around noon :)&lt;/p&gt;

&lt;p&gt;
Erik&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem in Interrupt</title><link>https://community.arm.com/thread/74819?ContentTypeID=1</link><pubDate>Tue, 13 Feb 2007 08:29:11 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:7f2e8630-bc02-4514-b82b-2c8325a28f2d</guid><dc:creator>ninja Z</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;Now let&amp;#39;s say you use the value as an array subscript, or
pointer offset.&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
He isn&amp;#39;t using the &lt;b&gt;var&lt;/b&gt; as an array subscript or a pointer
offset,is he?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem in Interrupt</title><link>https://community.arm.com/thread/47789?ContentTypeID=1</link><pubDate>Tue, 13 Feb 2007 05:04:05 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:fb6c2555-6e16-4c6a-b830-913c18481d05</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;pre&gt;
void main()
{
   sprintf(buffer,&amp;quot;%d&amp;quot;,(int)var);
   display(buffer,LINE1);

   // What happens next??!!
}
&lt;/pre&gt;

&lt;p&gt;
&lt;br /&gt;
What do you suppose will happen to your program when &lt;b&gt;main()&lt;/b&gt;
exits...?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem in Interrupt</title><link>https://community.arm.com/thread/47790?ContentTypeID=1</link><pubDate>Tue, 13 Feb 2007 04:47:53 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:8fa4dd46-bd58-4e1f-9ce6-3df7dbff6680</guid><dc:creator>Jonny Doin</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;&amp;quot;I am incrementing a variable in interrupt and displayng in
main program&amp;quot;&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
Consider your situation: you have a multibyte variable that is
being changed in the interrupt. This means that the interrupt will
break in the middle of any operation you may be doing with the
variable in the main program. That alone will not necessarily crash
your program, but might, depending for example on how you are relying
on domain values in your variable.&lt;/p&gt;

&lt;p&gt;
For instance, if you var is 0x00ff, your main program begins to
process it by taking the LSB (0xFF). Then the interrupt kicks in and
change the value to 0x0100. On return, the main program takes the
MSB, which is now 0x01, thus getting the value 0x01FF, instead of
0x0100. Now let&amp;#39;s say you use the value as an array subscript, or
pointer offset. That will shure produce a wild pointer and if you are
lucky will crash your program.&lt;/p&gt;

&lt;p&gt;
This is NOT a &amp;#39;problem&amp;#39; with the compiler or the CPU, it is an
effect of shared variables in multitasking systems. You should never
share variables in this manner. Search the internet for &amp;quot;atomic
operations&amp;quot; for detailed descriptions of what to do.&lt;/p&gt;

&lt;p&gt;
Another warning: your handler is compiled with register bank 2
function usage. If you have other functions with bank2 in the main
program, your system may crash, and that has nothing to do with the
shared var problem.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>