Hi all, I'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 "LPC17xx.h"
int main (void) { LPC_SC->PCONP |= 1 << 1; // Power up Timer 0 LPC_SC->PCLKSEL0 |= 1 << 2;
LPC_TIM0->MR0 = 1 << 23; // Give a value suitable for the LED blinking
LPC_TIM0->MCR |= 1 << 0; // Interrupt on Match 0 compare
LPC_TIM0->MCR |= 1 << 1; // Reset timer on Match 0
LPC_TIM0->TCR |= 1 << 1; // Manually Reset Timer 0 (forced)
LPC_TIM0->TCR &= ~(1 << 1); // Stop resetting the timer
LPC_TIM0->TCR |= 1 << 0; // Start timer
LPC_SC->PCONP |= ( 1 << 15 ); // Power up GPIO
LPC_GPIO1->FIODIR |= 1 << 29; // Put P1.29 into output mode
while (1); }
void TIM0_IRQHandler(void) { if ( (LPC_TIM0->IR & 0x01) == 0x01 ) // if MR0 interrupt
{ LPC_TIM0->IR |= 1 << 0; // Clear MR0 interrupt flag
LPC_GPIO1->FIOPIN ^= 1 << 29; // Toggle the LED } }
But when i debug the program and perform a single step debugging the led is not toggle(P1.29)- When TC=MR0 (in debug mode) it jump into startup_MPS_CMO.s and hang at the position as shown (->>>>). I'm using Keil uvsion with startup_MPS_CM0.s. May i know what's wrong with my program? THANK YOU.
Default_Handler PROC
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]
WDT_IRQHandler RTC_IRQHandler TIM0_IRQHandler TIM2_IRQHandler MCIA_IRQHandler MCIB_IRQHandler UART0_IRQHandler UART1_IRQHandler UART2_IRQHandler UART3_IRQHandler UART4_IRQHandler AACI_IRQHandler CLCD_IRQHandler ENET_IRQHandler USBDC_IRQHandler USBHC_IRQHandler CHLCD_IRQHandler FLEXRAY_IRQHandler CAN_IRQHandler LIN_IRQHandler I2C_IRQHandler CPU_CLCD_IRQHandler SPI_IRQHandler
->>>>> B .
ENDP
ALIGN
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)- When TC=MR0 (in debug mode) it jump into startup_MPS_CMO.s and hang at the position as shown (->>>>). May i know what's wrong with my program? THANK YOU.
#include <LPC17xx.H>
int main (void) {
LPC_SC->PCONP |= 1 << 1; // Power up Timer 0
LPC_SC->PCLKSEL0 |= 1 << 2; // Clock for timer = CCLK,
LPC_TIM0->MR0= 3124; // 1/(8000Hz) = 125 uS
NVIC_EnableIRQ(TIMER0_IRQn); // enable timer0 interrupt
void TIM0_IRQHandler (void) {
if ( (LPC_TIM0->IR & 0x01) == 0x01 ) // if MR0 interrupt
WHEN I PERFORM DEBUGGING- when TC=MR0 it jump into startup_MPS_CMO.s, it hang at (->>>>>>) [IN startup_MPS_CMO.s BELOW]
WDT_IRQHandler RTC_IRQHandler TIM0_IRQHandler TIM2_IRQHandler MCIA_IRQHandler MCIB_IRQHandler UART0_IRQHandler UART1_IRQHandler UART2_IRQHandler UART3_IRQHandler UART4_IRQHandler AACI_IRQHandler CLCD_IRQHandler ENET_IRQHandler USBDC_IRQHandler USBHC_IRQHandler CHLCD_IRQHandler FLEXRAY_IRQHandler CAN_IRQHandler LIN_IRQHandler I2C_IRQHandler CPU_CLCD_IRQHandler SPI_IRQHandler ->>>>>> B .
Dear Mike, It Hangs at "B". It hangs here because the controller is unable to locate you IRQ handler code.
Why are you bound to using startup_MPS_CMO.s
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.
Dear Dhaval,
Thanks for the guidance. When I ignore the startup file the following error occurred during linking process TESTBLINK.sct(7): error: L6236E: No section matches selector - no section to be FIRST/LAST.
If startup_LPC17xx.s is included following error displayed during linking process even after i changed the ISR to void TIMER0_IRQHandler (void) TESTBLINK.axf: Error: L6218E: Undefined symbol SystemInit (referred from startup_lpc17xx.o).
Therefore i removed startup_LPC17xx.s and replaced by startup_MPS_CM0.s . This gave a success in compiling and linking but hang at B as shown in previous post. Following is the code.
#include <LPC17xx.H> int main (void) { LPC_SC->PCONP |= 1 << 1; // Power up Timer 0 LPC_SC->PCLKSEL0 |= 1 << 2; // Clock for timer = CCLK, LPC_TIM0->MR0 = 1 << 23; // Give a value suitable for the LED blinking LPC_TIM0->TCR |= 1 << 1; // Manually Reset Timer 0 (forced); LPC_TIM0->TCR &= ~(1 << 1); // Stop resetting the timer // LPC_TIM0->PR = 0x00; // set prescaler to zero LPC_TIM0->MR0 = 3124; // 1/(8000Hz) = 125 uS = 3125-1 counts @ 40nS/tick //LPC_TIM0->MCR = 3; // Interupt and Reset on MR0: (1<<0) | (1<<1) LPC_TIM0->MCR |= 1 << 0; // Interrupt on Match 0 compare LPC_TIM0->MCR |= 1 << 1; // Reset timer on Match 0 NVIC_EnableIRQ(TIMER0_IRQn); // enable timer0 interrupt LPC_TIM0->TCR |= 1 << 0; // Start timer LPC_SC->PCONP |= ( 1 << 15 ); // Power up GPIO LPC_GPIO1->FIODIR |= 1 << 29; // Put P1.29 into output mode while (1); } void TIM0_IRQHandler (void) { if ( (LPC_TIM0->IR & 0x01) == 0x01 ) // if MR0 interrupt { LPC_TIM0->IR |= 1 << 0; // Clear MR0 interrupt flag LPC_GPIO1->FIOPIN ^= 1 << 29; // Toggle the LED } }
The error is descriptive and you can google or ask for assistance.
Any ways, SystemInit function is missing. hence add to your project system_LPC177x_8x or modify your startup_lpc17xx.s as following:
;******************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
Not to forget, the SystemInit function in the system_LPC17xx.c file, initialises all the clocks (core clock, peripheral clock, ...)
It's working! Thank you for all your guidance.
May I know what should I write to the setup settings of logic analyzer if I want to display the pin LPC_GPIO1->FIOPIN ^= 1 << 29 in the logic analyzer during debugging?
Thank you.