8 years, 5 months ago.

interrupt function questions

Why mbed compiler can not use the interrupt function? for example: int main() { uint8_t reserve[SIZE_STACK_FOR_IAP]; LPC_PINCON->PINSEL1 &= (0x00000003 << 16); LPC_GPIO0->FIODIR3|=0X01; LPC_GPIO0->FIOCLR3|=0X01; LPC_SC->PCONP|=0X00010000; printf("in RIT IRQ 1\n "); LPC_RIT->RICTRL=0X01; LPC_RIT->RICOMPVAL=384000000; LPC_RIT->RIMASK=0X00000000;

printf("in RIT IRQ 3\n "); NVIC_EnableIRQ(RIT_IRQn); LPC_RIT->RICTRL|=0X0A;

while(1) { printf("in RIT IRQ 5\n "); GPS_LEDFLASH(); wait(2); GPS_LEDOFF(); wait(2); deepsleep();

} return 0; }

void RIT_IRQHandler(void) { printf("in RIT IRQ\n "); LPC_RIT->RICTRL|=0X01; LPC_RIT->RICTRL&=0X07; GPS_LEDFLASH(); wait(2); GPS_LEDOFF(); LPC_RIT->RICTRL|=0X08;

}

the interrupt function can not enter

Question relating to:

Water Meter demo for C027N.

Just to improve the readability:

liu shuai's 1st code

int main()
{
   uint8_t reserve[SIZE_STACK_FOR_IAP];
   
   LPC_PINCON->PINSEL1 &= (0x00000003 << 16);
   LPC_GPIO0->FIODIR3|=0X01;
   LPC_GPIO0->FIOCLR3|=0X01;
   LPC_SC->PCONP|=0X00010000;
   printf("in RIT IRQ 1\n ");
   LPC_RIT->RICTRL=0X01;
   LPC_RIT->RICOMPVAL=384000000;
   LPC_RIT->RIMASK=0X00000000;
   printf("in RIT IRQ 3\n ");
   NVIC_EnableIRQ(RIT_IRQn);
   LPC_RIT->RICTRL|=0X0A;
   
   while(1)
   {
      printf("in RIT IRQ 5\n ");
      GPS_LEDFLASH();
      wait(2);
      GPS_LEDOFF();
      wait(2);
      deepsleep();
   }
   
   return 0;
}


void RIT_IRQHandler(void)
{
   printf("in RIT IRQ\n ");
   LPC_RIT->RICTRL|=0X01;
   LPC_RIT->RICTRL&=0X07;
   GPS_LEDFLASH();
   wait(2);
   GPS_LEDOFF();
   LPC_RIT->RICTRL|=0X08;
}

and

liu shuai's 2nd code

int main()
{
   LPC_SC->PCONP|=0X00010000;
   printf("in RIT IRQ 1\n ");
   LPC_RIT->RICTRL=0X01;
   LPC_RIT->RICOMPVAL=384000000;
   LPC_RIT->RIMASK=0X00000000;
   printf("in RIT IRQ 3\n ");
   NVIC_EnableIRQ(RIT_IRQn);
   LPC_RIT->RICTRL|=0X0A;

   while(1)
   {
      printf("in RIT IRQ 5\n ");
      wait(2);
   }
}

void RIT_IRQHandler(void)
{
   printf("in RIT IRQ\n ");
   LPC_RIT->RICTRL|=0X01;
   LPC_RIT->RICTRL&=0X07;
   GPS_LEDFLASH();
   wait(2);
   GPS_LEDOFF();
   LPC_RIT->RICTRL|=0X08;
}
posted by Miloje Zecevic 05 Nov 2015

sorry,After the issue of the code format will change。Yes, this is my code in the original format, what should I do to get the right to enter the interrupt handler。Now is the interrupt generated but can not enter the interrupt handler

posted by liu shuai 05 Nov 2015

2 Answers

8 years, 5 months ago.

Hi Liu,

if you want to use the predefined IRQ-Vector you have to declare it as extern for the compiler to see it:

extern "C" void RIT_IRQHandler(void) __irq {
   /* your handler code */
}

Otherwise you can use any void/void-function as handler by calling NVIC_SetVector:

void irq_handler(void) {
   /* your handler code */
}

NVIC_SetVector(RIT_IRQn, (uint32_t)&irq_handler);

Best regards
Neni

Accepted Answer

You have solved my problem very well,Thank you very much@Neni,Also thanks to all the other people who helped me solve the problem.

posted by liu shuai 06 Nov 2015
8 years, 5 months ago.

First of all, please use <<code>> and <</code>> (on seperate lines) to make it readable.

Second, the mbed compiler can do interrupts, so you have an error in your code. Does your code run? Where does it fail? What did you try to debug it?

int main() {

LPC_SC->PCONP|=0X00010000; printf("in RIT IRQ 1\n "); LPC_RIT->RICTRL=0X01; LPC_RIT->RICOMPVAL=384000000; LPC_RIT->RIMASK=0X00000000;

printf("in RIT IRQ 3\n "); NVIC_EnableIRQ(RIT_IRQn); LPC_RIT->RICTRL|=0X0A;

while(1) { printf("in RIT IRQ 5\n ");

wait(2);

}

}

void RIT_IRQHandler(void) { printf("in RIT IRQ\n "); LPC_RIT->RICTRL|=0X01; LPC_RIT->RICTRL&=0X07; GPS_LEDFLASH(); wait(2); GPS_LEDOFF(); LPC_RIT->RICTRL|=0X08;

}

The code is compiled and debugged.Log “in RIT IRQ 5” can output 8times,That's 16 seconds. Then the program was dead. I think the interrupt response has been made.But the interrupt entry function is not correct, the interrupt handler function can not be executed correctly。 this is a "RIT interrupt"。What should I do in MBED to find the start function like LPC17XX.S,To confirm the interrupt handler name

posted by liu shuai 05 Nov 2015