<?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>array inside interrupt function</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/14244/array-inside-interrupt-function</link><description> I having trouble sending data out under interrupts from a buffer. 
 
The buffer was declared in xdata and i have a counter that is used to index into it. 
 
So when an interrupt occurs, the data is loaded into my SPI tx buffer, ie 
SPIBUF = txbuffer</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: array inside interrupt function</title><link>https://community.arm.com/thread/129692?ContentTypeID=1</link><pubDate>Tue, 26 Jun 2001 19:22:33 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:7a47cf05-2da9-480d-a341-967ac9198873</guid><dc:creator>David Pleydell</dc:creator><description>&lt;p&gt;Thanks for the info.&lt;br /&gt;
&lt;br /&gt;
The disassembly looked funny because of the MOV A, #QueueSize which is another variable declared somewhere else.  &lt;br /&gt;
The listing made sense, the QueueSize in the disassembly though confused me.&lt;br /&gt;
&lt;br /&gt;
David&lt;br /&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: array inside interrupt function</title><link>https://community.arm.com/thread/121609?ContentTypeID=1</link><pubDate>Tue, 26 Jun 2001 19:09:42 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:2fece7b7-2842-4c4f-9a9b-0d67ff7e5b2c</guid><dc:creator>Jon Ward</dc:creator><description>&lt;p&gt;From that assembly listing, everything looks exactly correct.&lt;br /&gt;
&lt;br /&gt;
My guess is that your memory doesn&amp;#39;t work correctly (or as you expect).&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;
552: txbuffer[4] = 0x44;&lt;br /&gt;
c:0x1938 A3 INC DPTR;&lt;br /&gt;
c:0x1939 7444 MOV A,#QueueSize(0x44)&lt;br /&gt;
c:0x193b F0 MOVX @DPTR,A&lt;br /&gt;
553: P1 = txbuffer[0];&lt;br /&gt;
&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
This is all exactly correct.  The debugger disassembles your code.  The disassembly EXACTLY matches the listing that you provided.  Which, I might add, is exactly what it should be.&lt;br /&gt;
&lt;br /&gt;
This kinda reminds me of a project I looked at were the programmer duplicated every move into R0.  For example,&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;
   mov a, #12h
   mov r0, a
   mov r0, a

   mov a, @r0
&lt;/pre&gt;
&lt;br /&gt;
When asked why the double move into r0, he responded, &amp;quot;Because the first one didn&amp;#39;t take.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
My question was, &amp;quot;If the first mov r0 didn&amp;#39;t take, how do you know that the second one always would?&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Jon&lt;/b&gt;&lt;br /&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: array inside interrupt function</title><link>https://community.arm.com/thread/109844?ContentTypeID=1</link><pubDate>Tue, 26 Jun 2001 18:32:59 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:338abec3-8f6a-48de-9690-e8a563cedaca</guid><dc:creator>David Pleydell</dc:creator><description>&lt;p&gt;Yes that is correct.&lt;br /&gt;
&lt;br /&gt;
My buffer is:&lt;br /&gt;
xdata unsigned char txbuffer[BUFFSIZE]&lt;br /&gt;
&lt;br /&gt;
This is from the list file.&lt;br /&gt;
                                           ; SOURCE LINE # 548&lt;br /&gt;
0044 900000     R     MOV DPTR,#txbuffer&lt;br /&gt;
0047 74AA              MOV     A,#0AAH&lt;br /&gt;
0049 F0                MOVX    @DPTR,A&lt;br /&gt;
&lt;br /&gt;
                                           ; SOURCE LINE # 549&lt;br /&gt;
004A A3                INC     DPTR&lt;br /&gt;
004B 7411              MOV     A,#011H&lt;br /&gt;
004D F0                MOVX    @DPTR,A&lt;br /&gt;
   &lt;br /&gt;
                                           ; SOURCE LINE # 550&lt;br /&gt;
004E A3                INC     DPTR&lt;br /&gt;
004F 7422              MOV     A,#022H&lt;br /&gt;
0051 F0                MOVX    @DPTR,A&lt;br /&gt;
&lt;br /&gt;
                                           ; SOURCE LINE # 551&lt;br /&gt;
0052 A3                INC     DPTR&lt;br /&gt;
0053 7433              MOV     A,#033H&lt;br /&gt;
0055 F0                MOVX    @DPTR,A&lt;br /&gt;
&lt;br /&gt;
                                           ; SOURCE LINE # 552&lt;br /&gt;
0056 A3                INC     DPTR&lt;br /&gt;
0057 7444              MOV     A,#044H&lt;br /&gt;
0059 F0                MOVX    @DPTR,A&lt;br /&gt;
&lt;br /&gt;
                                           ; SOURCE LINE # 553&lt;br /&gt;
005A 900000      R     MOV     DPTR,#txbuffer&lt;br /&gt;
005D E0                MOVX    A,@DPTR&lt;br /&gt;
005E F590              MOV     P1,A&lt;br /&gt;
                                           ; SOURCE LINE # 567&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 548   1      	txbuffer[0] = 0xaa; &lt;br /&gt;
 549   1        txbuffer[1] = 0x11;&lt;br /&gt;
 550   1      	txbuffer[2] = 0x22;&lt;br /&gt;
 C51 COMPILER V6.14  &lt;br /&gt;
 551   1      	txbuffer[3] = 0x33;&lt;br /&gt;
 552   1      	txbuffer[4] = 0x44;&lt;br /&gt;
 553   1      	P1 = txbuffer[0];&lt;br /&gt;
&lt;br /&gt;
The symbols in dscope when looking at the disassembly window make little sense, looks like other variables have been moved, something strange with dscope.&lt;br /&gt;
For example:&lt;br /&gt;
552: txbuffer[4] = 0x44;&lt;br /&gt;
c:0x1938 A3    INC DPTR;&lt;br /&gt;
c:0x1939 7444  MOV A,#QueueSize(0x44)&lt;br /&gt;
c:0x193b F0    MOVX @DPTR,A&lt;br /&gt;
553: P1 = txbuffer[0];&lt;br /&gt;
Not sure about that one.&lt;br /&gt;
&lt;br /&gt;
This is from the memory map:&lt;br /&gt;
txbuffer . . . . . . . . . . . . . . .  PUBLIC   XDATA  ARRAY    0065H  50&lt;br /&gt;
&lt;br /&gt;
I guess it depends on whether DPTR has been loaded with the correct address for txbuffer.&lt;br /&gt;
&lt;br /&gt;
David&lt;br /&gt;
&lt;br /&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: array inside interrupt function</title><link>https://community.arm.com/thread/84112?ContentTypeID=1</link><pubDate>Tue, 26 Jun 2001 17:22:40 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:e4f1b358-9bd9-4e2a-9671-99ad0cdaf958</guid><dc:creator>Jon Young</dc:creator><description>&lt;p&gt;One guess is that txbuffer points to &amp;quot;nowhere&amp;quot;.  What is being read from the external data bus is only the charge left from a previous access.&lt;br /&gt;
&lt;br /&gt;
Try&lt;br /&gt;
&lt;pre&gt;
txbuffer[0] = 0xaa; 
txbuffer[1] = 0x11;
P1 = txbuffer[0];
&lt;/pre&gt; &lt;br /&gt;
&lt;br /&gt;
If you get an answer of 0x11, check the address of txbuffer.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: array inside interrupt function</title><link>https://community.arm.com/thread/109828?ContentTypeID=1</link><pubDate>Tue, 26 Jun 2001 08:00:41 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:480dde19-4397-419f-a5bd-2b5034a0fac8</guid><dc:creator>Jon Ward</dc:creator><description>&lt;p&gt;Better yet, what&amp;#39;s the assembler code generated for the &amp;quot;example&amp;quot; code you posted?&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Jon&lt;/b&gt;&lt;br /&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: array inside interrupt function</title><link>https://community.arm.com/thread/94800?ContentTypeID=1</link><pubDate>Tue, 26 Jun 2001 03:09:42 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:1f3d876a-f1cf-4165-8110-dcdf7df733d7</guid><dc:creator>Andrew Neil</dc:creator><description>&lt;p&gt;So you&amp;#39;re saying this works (&lt;i&gt;ie,&lt;/i&gt; 0xAA appears on the 7 segment displays):&lt;pre&gt;
txbuffer[0] = 0xaa; 
txbuffer[1] = 0x11;
txbuffer[2] = 0x22;
txbuffer[0] = 0xaa; 
P1 = txbuffer[0];&lt;/pre&gt;
But this doesn&amp;#39;t work (0 appears on the 7 segment displays):&lt;pre&gt;
txbuffer[0] = 0xaa; 
txbuffer[1] = 0x11;
txbuffer[2] = 0x22;
P1 = txbuffer[0];&lt;/pre&gt;
&lt;br /&gt;
Sounds like something funny with your ASIC&amp;#39;s  memory addressing?&lt;br /&gt;
&lt;br /&gt;
What is the full &amp;#39;C&amp;#39; definition of txbuffer?&lt;br /&gt;
&lt;br /&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: array inside interrupt function</title><link>https://community.arm.com/thread/53740?ContentTypeID=1</link><pubDate>Mon, 25 Jun 2001 23:12:46 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:79aadb8d-6533-451c-a1aa-592251b2c031</guid><dc:creator>David Pleydell</dc:creator><description>&lt;p&gt;The external memory is inside an ASIC.  I actually found something interesting.&lt;br /&gt;
&lt;br /&gt;
txbuffer[0] = 0xaa; &lt;br /&gt;
txbuffer[1] = 0x11;&lt;br /&gt;
txbuffer[2] = 0x22;&lt;br /&gt;
&lt;br /&gt;
// Try transmitting data;&lt;br /&gt;
// NB 1 - txbuffer[0] = 0xaa; &lt;br /&gt;
P1 = txbuffer[0];  // P1 has 7 segment displays connected to it.&lt;br /&gt;
&lt;br /&gt;
If i don&amp;#39;t include NB 1 just before writing it to P1 then it displays 0x00 but if i put NB 1 in and hence initial location 0 again it displays the correct value.&lt;br /&gt;
&lt;br /&gt;
Is this something funny with the compiler or the ASIC?&lt;br /&gt;
&lt;br /&gt;
David&lt;br /&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: array inside interrupt function</title><link>https://community.arm.com/thread/37632?ContentTypeID=1</link><pubDate>Mon, 25 Jun 2001 22:43:26 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:655cdda9-6631-4cb2-8892-052eaeee6d4d</guid><dc:creator>Jon Young</dc:creator><description>&lt;p&gt;1) Check if your external memory is working. Try:&lt;br /&gt;
&lt;pre&gt;
..
txbuffer[0] = 0xAB;
..
SPIBUF = txbuffer[0];
index++;
&lt;/pre&gt;
&lt;br /&gt;
2) Check if your indexing is correct.&lt;br /&gt;
Verify &amp;quot;SPIBUF = index;&amp;quot; generates &amp;quot;0,1,2,...&amp;quot;, not just something.&lt;br /&gt;
&lt;br /&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>