<?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 with Timer0 interrupt</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/40247/problem-with-timer0-interrupt</link><description> 
Hi all, 
I&amp;#39;m a newbie on LPC1768 and copy the following program from a site -
the program is to blink an LED using timer interrupt 0. The program
is as follow 

 
#include &amp;quot;LPC17xx.h&amp;quot; 

 
int main (void) 
{ LPC_SC-&amp;gt;PCONP |= 1 &amp;lt;&amp;lt; 1; // Power up Timer</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: Problem with Timer0 interrupt</title><link>https://community.arm.com/thread/147900?ContentTypeID=1</link><pubDate>Tue, 02 Jul 2013 02:21:48 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:b3f12a33-7545-4c82-9184-9bea3b95fb13</guid><dc:creator>Mike Lee</dc:creator><description>&lt;p&gt;&lt;p&gt;
Hi Dhaval,&lt;br /&gt;
I have read the posted link. I still don&amp;#39;t know how to initialize the
pin LPC_GPIO1-&amp;gt;FIOPIN pin 29. If it&amp;#39;s a 8051 microcontroller, I
just initialize as e.g. P1.0 in the setup of the logic analyzer. I
have try to key in LPC_GPIO1-&amp;gt;FIOPIN and mask the bit by
0x20000000 with display type Bit. The pin 29 in the logic analyzer
didn&amp;#39;t toggle. May I know my mistake? Thank you.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem with Timer0 interrupt</title><link>https://community.arm.com/thread/145529?ContentTypeID=1</link><pubDate>Mon, 01 Jul 2013 01:05:52 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:be1bd912-3582-43d8-b196-f8f2a94ed3e2</guid><dc:creator>Mike Lee</dc:creator><description>&lt;p&gt;&lt;p&gt;
Dear Dhaval,&lt;/p&gt;

&lt;p&gt;
May I know what should I write to the setup settings of logic
analyzer if I want to display the pin &lt;i&gt;LPC_GPIO1-&amp;gt;FIOPIN ^= 1
&amp;lt;&amp;lt; 29&lt;/i&gt; in the logic analyzer during debugging?&lt;/p&gt;

&lt;p&gt;
Thank you.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem with Timer0 interrupt</title><link>https://community.arm.com/thread/143421?ContentTypeID=1</link><pubDate>Mon, 24 Jun 2013 02:25:22 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:902f895a-31e7-4659-95ae-d7e757d4412d</guid><dc:creator>Mike Lee</dc:creator><description>&lt;p&gt;&lt;p&gt;
Dear Dhaval,&lt;/p&gt;

&lt;p&gt;
It&amp;#39;s working! Thank you for all your guidance.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem with Timer0 interrupt</title><link>https://community.arm.com/thread/140591?ContentTypeID=1</link><pubDate>Sun, 23 Jun 2013 20:56:49 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:83480915-4147-487f-8c30-93e3c921084f</guid><dc:creator>Ash J</dc:creator><description>&lt;p&gt;&lt;p&gt;
The error is descriptive and you can google or ask for
assistance.&lt;/p&gt;

&lt;p&gt;
Any ways, SystemInit function is missing. hence add to your
project &lt;i&gt;system_LPC177x_8x&lt;/i&gt; or modify your startup_lpc17xx.s as
following:&lt;/p&gt;

&lt;pre&gt;
;******************Use this code if system_LPC17xx.c file is not used****************************
Reset_Handler   PROC
                EXPORT  Reset_Handler             [WEAK]
                IMPORT  __main
                LDR     R0, =__main
                BX      R0
                ENDP

;******************Use this code if system_LPC17xx.c file is used****************************
;Reset_Handler   PROC
;                EXPORT  Reset_Handler             [WEAK]
;                IMPORT  SystemInit
;                IMPORT  __main
;                LDR     R0, =SystemInit
;                BLX     R0
;                LDR     R0, =__main
;                BX      R0
;                ENDP
&lt;/pre&gt;

&lt;p&gt;
Not to forget, the SystemInit function in the system_LPC17xx.c
file, initialises all the clocks (core clock, peripheral clock,
...)&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem with Timer0 interrupt</title><link>https://community.arm.com/thread/131277?ContentTypeID=1</link><pubDate>Sat, 22 Jun 2013 20:54:11 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:660009ac-2b3d-48b4-9c59-ccf87c9aebeb</guid><dc:creator>Mike Lee</dc:creator><description>&lt;p&gt;&lt;p&gt;
Dear Dhaval,&lt;/p&gt;

&lt;p&gt;
Thanks for the guidance. When I ignore the startup file the
following error occurred during linking process&lt;br /&gt;
TESTBLINK.sct(7): error: L6236E: No section matches selector - no
section to be FIRST/LAST.&lt;/p&gt;

&lt;p&gt;
If &lt;i&gt;startup_LPC17xx.s&lt;/i&gt; is included following error displayed
during linking process even after i changed the ISR to &lt;i&gt;void
TIMER0_IRQHandler (void)&lt;/i&gt;&lt;br /&gt;
TESTBLINK.axf: Error: L6218E: Undefined symbol SystemInit (referred
from startup_lpc17xx.o).&lt;/p&gt;

&lt;p&gt;
Therefore i removed &lt;i&gt;startup_LPC17xx.s&lt;/i&gt; and replaced by
&lt;i&gt;startup_MPS_CM0.s&lt;/i&gt; . This gave a success in compiling and
linking but hang at &lt;b&gt;B&lt;/b&gt; as shown in previous post. Following is
the code.&lt;/p&gt;

&lt;pre&gt;
#include &amp;lt;LPC17xx.H&amp;gt;

int main (void)
{

    LPC_SC-&amp;gt;PCONP |= 1 &amp;lt;&amp;lt; 1; // Power up Timer 0
    LPC_SC-&amp;gt;PCLKSEL0 |= 1 &amp;lt;&amp;lt; 2; // Clock for timer = CCLK,


    LPC_TIM0-&amp;gt;MR0 = 1 &amp;lt;&amp;lt; 23; // Give a value suitable for the LED blinking

          LPC_TIM0-&amp;gt;TCR |= 1 &amp;lt;&amp;lt; 1; // Manually Reset Timer 0 (forced);
    LPC_TIM0-&amp;gt;TCR &amp;amp;= ~(1 &amp;lt;&amp;lt; 1); // Stop resetting the timer
   // LPC_TIM0-&amp;gt;PR           = 0x00;               // set prescaler to zero
    LPC_TIM0-&amp;gt;MR0          = 3124;            // 1/(8000Hz) = 125 uS = 3125-1 counts @ 40nS/tick
    //LPC_TIM0-&amp;gt;MCR          = 3;          // Interupt and Reset on MR0: (1&amp;lt;&amp;lt;0) | (1&amp;lt;&amp;lt;1)
                LPC_TIM0-&amp;gt;MCR |= 1 &amp;lt;&amp;lt; 0; // Interrupt on Match 0 compare
          LPC_TIM0-&amp;gt;MCR |= 1 &amp;lt;&amp;lt; 1; // Reset timer on Match 0
    NVIC_EnableIRQ(TIMER0_IRQn); // enable timer0 interrupt


    LPC_TIM0-&amp;gt;TCR |= 1 &amp;lt;&amp;lt; 0; // Start timer
    LPC_SC-&amp;gt;PCONP |= ( 1 &amp;lt;&amp;lt; 15 ); // Power up GPIO
    LPC_GPIO1-&amp;gt;FIODIR |= 1 &amp;lt;&amp;lt; 29; // Put P1.29 into output mode


    while (1);
}

void TIM0_IRQHandler (void)
{

    if ( (LPC_TIM0-&amp;gt;IR &amp;amp; 0x01) == 0x01 ) // if MR0 interrupt
    {
        LPC_TIM0-&amp;gt;IR |= 1 &amp;lt;&amp;lt; 0; // Clear MR0 interrupt flag
        LPC_GPIO1-&amp;gt;FIOPIN ^= 1 &amp;lt;&amp;lt; 29; // Toggle the LED
    }
}

&lt;/pre&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem with Timer0 interrupt</title><link>https://community.arm.com/thread/128219?ContentTypeID=1</link><pubDate>Sat, 22 Jun 2013 03:58:44 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:ad5370aa-15b2-4b65-aa66-6345677278f9</guid><dc:creator>Ash J</dc:creator><description>&lt;p&gt;&lt;p&gt;
Dear Mike,&lt;br /&gt;
It Hangs at &lt;b&gt;&amp;quot;B&amp;quot;&lt;/b&gt;. It hangs here because the controller is
unable to locate you IRQ handler code.&lt;/p&gt;

&lt;p&gt;
Why are you bound to using &lt;b&gt;startup_MPS_CMO.s&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;
Also, refer to the posting tips that are given just above the
message box. and post the code accordingly. The code you have posted
is unreadable.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem with Timer0 interrupt</title><link>https://community.arm.com/thread/117331?ContentTypeID=1</link><pubDate>Sat, 22 Jun 2013 02:52:59 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:79d7c1d1-5c83-4d13-95b4-e3aafe49e9dd</guid><dc:creator>Mike Lee</dc:creator><description>&lt;p&gt;&lt;p&gt;
Hi...thank you. I have modified the program as shown. But I still
have the same problem where But when i debug the program and perform
a single step debugging the led is not toggle(P1.29)-&lt;br /&gt;
When TC=MR0 (in debug mode) it jump into startup_MPS_CMO.s and hang
at the position as shown (-&amp;gt;&amp;gt;&amp;gt;&amp;gt;).&lt;br /&gt;
May i know what&amp;#39;s wrong with my program? THANK YOU.&lt;/p&gt;

&lt;p&gt;
#include &amp;lt;LPC17xx.H&amp;gt;&lt;/p&gt;

&lt;p&gt;
int main (void)&lt;br /&gt;
{&lt;/p&gt;

&lt;p&gt;
LPC_SC-&amp;gt;PCONP |= 1 &amp;lt;&amp;lt; 1; // Power up Timer 0&lt;/p&gt;

&lt;p&gt;
LPC_SC-&amp;gt;PCLKSEL0 |= 1 &amp;lt;&amp;lt; 2; // Clock for timer =
CCLK,&lt;/p&gt;

&lt;p&gt;
LPC_TIM0-&amp;gt;MR0 = 1 &amp;lt;&amp;lt; 23; // Give a value suitable for the
LED blinking&lt;/p&gt;

&lt;p&gt;
LPC_TIM0-&amp;gt;TCR |= 1 &amp;lt;&amp;lt; 1; // Manually Reset Timer 0
(forced)&lt;/p&gt;

&lt;p&gt;
LPC_TIM0-&amp;gt;TCR &amp;amp;= ~(1 &amp;lt;&amp;lt; 1); // Stop resetting the
timer&lt;/p&gt;

&lt;p&gt;
LPC_TIM0-&amp;gt;MR0= 3124; // 1/(8000Hz) = 125 uS&lt;/p&gt;

&lt;p&gt;
LPC_TIM0-&amp;gt;MCR |= 1 &amp;lt;&amp;lt; 0; // Interrupt on Match 0
compare&lt;/p&gt;

&lt;p&gt;
LPC_TIM0-&amp;gt;MCR |= 1 &amp;lt;&amp;lt; 1; // Reset timer on Match 0&lt;/p&gt;

&lt;p&gt;
NVIC_EnableIRQ(TIMER0_IRQn); // enable timer0 interrupt&lt;/p&gt;

&lt;p&gt;
LPC_TIM0-&amp;gt;TCR |= 1 &amp;lt;&amp;lt; 0; // Start timer&lt;/p&gt;

&lt;p&gt;
LPC_SC-&amp;gt;PCONP |= ( 1 &amp;lt;&amp;lt; 15 ); // Power up GPIO&lt;/p&gt;

&lt;p&gt;
LPC_GPIO1-&amp;gt;FIODIR |= 1 &amp;lt;&amp;lt; 29; // Put P1.29 into output
mode&lt;/p&gt;

&lt;p&gt;
while (1);&lt;br /&gt;
}&lt;/p&gt;

&lt;p&gt;
void TIM0_IRQHandler (void)&lt;br /&gt;
{&lt;/p&gt;

&lt;p&gt;
if ( (LPC_TIM0-&amp;gt;IR &amp;amp; 0x01) == 0x01 ) // if MR0
interrupt&lt;/p&gt;

&lt;p&gt;
{ LPC_TIM0-&amp;gt;IR |= 1 &amp;lt;&amp;lt; 0; // Clear MR0 interrupt flag&lt;/p&gt;

&lt;p&gt;
LPC_GPIO1-&amp;gt;FIOPIN ^= 1 &amp;lt;&amp;lt; 29; // Toggle the LED }&lt;br /&gt;
}&lt;/p&gt;

&lt;p&gt;
WHEN I PERFORM DEBUGGING- when TC=MR0 it jump into
startup_MPS_CMO.s, it hang at (-&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;) [IN
startup_MPS_CMO.s BELOW]&lt;/p&gt;

&lt;p&gt;
Default_Handler PROC&lt;/p&gt;

&lt;p&gt;
EXPORT WDT_IRQHandler [WEAK] EXPORT RTC_IRQHandler [WEAK] EXPORT
TIM0_IRQHandler [WEAK] EXPORT TIM2_IRQHandler [WEAK] EXPORT
MCIA_IRQHandler [WEAK] EXPORT MCIB_IRQHandler [WEAK] EXPORT
UART0_IRQHandler [WEAK] EXPORT UART1_IRQHandler [WEAK] EXPORT
UART2_IRQHandler [WEAK] EXPORT UART3_IRQHandler [WEAK] EXPORT
UART4_IRQHandler [WEAK] EXPORT AACI_IRQHandler [WEAK] EXPORT
CLCD_IRQHandler [WEAK] EXPORT ENET_IRQHandler [WEAK] EXPORT
USBDC_IRQHandler [WEAK] EXPORT USBHC_IRQHandler [WEAK] EXPORT
CHLCD_IRQHandler [WEAK] EXPORT FLEXRAY_IRQHandler [WEAK] EXPORT
CAN_IRQHandler [WEAK] EXPORT LIN_IRQHandler [WEAK] EXPORT
I2C_IRQHandler [WEAK] EXPORT CPU_CLCD_IRQHandler [WEAK] EXPORT
SPI_IRQHandler [WEAK]&lt;/p&gt;

&lt;p&gt;
WDT_IRQHandler&lt;br /&gt;
RTC_IRQHandler&lt;br /&gt;
TIM0_IRQHandler&lt;br /&gt;
TIM2_IRQHandler&lt;br /&gt;
MCIA_IRQHandler&lt;br /&gt;
MCIB_IRQHandler&lt;br /&gt;
UART0_IRQHandler&lt;br /&gt;
UART1_IRQHandler&lt;br /&gt;
UART2_IRQHandler&lt;br /&gt;
UART3_IRQHandler&lt;br /&gt;
UART4_IRQHandler&lt;br /&gt;
AACI_IRQHandler&lt;br /&gt;
CLCD_IRQHandler&lt;br /&gt;
ENET_IRQHandler&lt;br /&gt;
USBDC_IRQHandler&lt;br /&gt;
USBHC_IRQHandler&lt;br /&gt;
CHLCD_IRQHandler&lt;br /&gt;
FLEXRAY_IRQHandler&lt;br /&gt;
CAN_IRQHandler&lt;br /&gt;
LIN_IRQHandler&lt;br /&gt;
I2C_IRQHandler&lt;br /&gt;
CPU_CLCD_IRQHandler&lt;br /&gt;
SPI_IRQHandler&lt;br /&gt;
-&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; B .&lt;/p&gt;

&lt;p&gt;
ENDP&lt;/p&gt;

&lt;p&gt;
ALIGN&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem with Timer0 interrupt</title><link>https://community.arm.com/thread/117327?ContentTypeID=1</link><pubDate>Sat, 22 Jun 2013 01:43:58 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:890430ec-c4ae-4a3b-bec5-c235e66d98bf</guid><dc:creator>Ash J</dc:creator><description>&lt;p&gt;&lt;p&gt;
Why are you using &lt;b&gt;startup_MPS_CM0.s&lt;/b&gt;. Its a start-up file
for Cortex M0 architecture (Dont know what the architectural
structure is).&lt;br /&gt;
LPC1768 is a Cortex M3 architecture.&lt;br /&gt;
&lt;i&gt;_I would recommend you to use LPC17xx start-up file unless you
know what you are doing_&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
PS: Try your code execution with LPC17xx start-up. Does it run
properly??&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem with Timer0 interrupt</title><link>https://community.arm.com/thread/107168?ContentTypeID=1</link><pubDate>Sat, 22 Jun 2013 01:36:10 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:60fb5b32-6bb5-470a-aa4c-ee97d9ab7760</guid><dc:creator>Ash J</dc:creator><description>&lt;p&gt;&lt;p&gt;
Have you enabled the Timer0 Interrupt in NVIC?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem with Timer0 interrupt</title><link>https://community.arm.com/thread/81292?ContentTypeID=1</link><pubDate>Fri, 21 Jun 2013 23:57:37 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:229906f0-687d-4edf-b933-ee0791ca03e0</guid><dc:creator>Mike Lee</dc:creator><description>&lt;p&gt;&lt;p&gt;
Thank you for replying. I&amp;#39;m using startup_MPS_CM0.s at not
startup_lpc17xx.s. The interrupt handler used by this
startup_MPS_CM0.s is TIM0_IRQHandler. It can&amp;#39;t enter to the interrupt
service routine!&lt;br /&gt;
Thanks.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem with Timer0 interrupt</title><link>https://community.arm.com/thread/62019?ContentTypeID=1</link><pubDate>Thu, 20 Jun 2013 22:33:44 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:729ea53d-f3a7-4e4a-93c2-ec740042c41a</guid><dc:creator>Ash J</dc:creator><description>&lt;p&gt;&lt;p&gt;
What is the Vector name in the startup_lpc17xx.s file?&lt;br /&gt;
Is it &lt;b&gt;TIM0_Handler&lt;/b&gt;?&lt;/p&gt;

&lt;p&gt;
Use the same name.&lt;/p&gt;

&lt;p&gt;
Eg:&lt;/p&gt;

&lt;pre&gt;
__Vectors
         DCD     TIMER0_IRQHandler         ; 17: Timer0


Default_Handler PROC
                EXPORT  TIMER0_IRQHandler         [WEAK]
&lt;/pre&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>