I don't know why my interrupt handler doesn't work... can anyone of you please help me? ): Below is my code (the highlighted part is my interrupt handler):

#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
#include "IIC.h"
#include "LEDs.h"
#include "ICG.h"
#include "Delays.h"
#include "initialization.h"
#include "MPR083.h"
#include "MPRIIC.h"
#include "TPMs.h"
#include "IRQ_ms_User.h"
#include "IRQ_ms_TPM1C0.h"
#include "LC60IIC_IRQ.h"

unsigned char ucIIC_SlaveData;
unsigned char ucIIC_LastSlaveData;
unsigned char ucIIC_AckStatus;
unsigned char ucMPRIIC;
unsigned char ucIIC_DataRcvd;
unsigned char ucPadNumber;
unsigned char ucLC60_Flag=0;
unsigned char uctestcnt=0;  //test

struct mpr_st stAns;

interrupt VectorNumber_Vtpm1ch0 void TPM1C0IRQ(){ //Timer IRQ backbone handler
  TPM1C0_setNextIRQ(CNT_10MHZ_FOR_1MS); //prepare for next ms IRQ
  IRQ_ms_Handler_(); //IRQ Handler to call user functions every 1,10,100,and 1000 ms
}

interrupt VectorNumber_Virq void IRQ_IIC(){ //IIC interrupt upon touch
  IRQSC_IRQACK=1;//1=Clear the IRQ Flag in LC60; 
  LED4_turnOn();
  ucLC60_Flag=1;  
  uctestcnt++;
  LED4_turnOff();  
} 

void main(void) {
  SOPT1_COPE=0;               // Disable watchdog timer  
  ICG_setBusClk(ICGC2_10MHZ); // 10.468 Mhz,wait 0.2s
  PTAD_PTAD3=0;               // 1=off display(~DSEL)  
  LED1_init();
  LED4_init();
  LED5_init();
  IIC_init();                 // EnableIIC,90kbs;noIRQ,master-mode;~ack;sendSTART+STOP;include delay for stabilisation
  IRQ_init();
  MPR_init();

  //-----TPM INITIALIAZATION------------------------                             
  TPM1_init();           // Use BusClk/16;O/p compare mode;no overflow IRQ
  TPM1C0_init();         // TimerCh0 TPM1C0/PTC2; enable IRQ
  TPM1C0_setToggleMode();// Toggle TPM1C0/PTC2  J101p13

  //-----ENABLE INTERRUPT---------------------------
  TPM1C0_enableIRQ();    // Enable TPM2Ch0 interrupt    
  //IRQ_IIC();
  IRQ_enable();
  MPRIIC_IRQ_enable();
  EnableInterrupts; 

  for(;;) {
    if(ucLC60_Flag==1){        
        LED1_turnOn();
        ucPadNumber=MPR_readPadNo(); //Return pad position
        MPRIIC_clear();  
        ucLC60_Flag=0; //RESET
        LED1_turnOff();
   }  
  }// loop forever 
}

I will be very glad if any of you can help me.... thank you very much...

Recommended Answers

All 9 Replies

It would help if you used code-tags so we could actually read your code.

Also: What microcontroller is this? And post a link to it's datasheet, I'm too lazy to search for it myself ;)

It would help if you used code-tags so we could actually read your code.

Also: What microcontroller is this? And post a link to it's datasheet, I'm too lazy to search for it myself ;)

Reply:
The micro-controller that I am using is: DEMO9S08LC60. I/C using for this project is MPR083 which uses IIC.

Links for the datasheet:
1. http://www.freescale.com/files/sensors/doc/data_sheet/MPR083.pdf
2.
http://www.freescale.com/files/microcontrollers/doc/data_sheet/MC9S08LC60.pdf

So how do you know that the handler isn't working? If the answer is: I can't see the LED blink, then that's because the ontime is to small to see with the naked eye.

Does interrupt VectorNumber_Vtpm1ch0 void TPM1C0IRQ() work?

Do your I2C functions work at all? Did you test them?

Put a counter on the interrupt and pre-clear, then after a short while, examine the counter and see if it is non zero!

Put a counter on the interrupt and pre-clear, then after a short while, examine the counter and see if it is non zero!

You mean like the uctestcnt++; he put in the interrupt-handler? ;)

So how do you know that the handler isn't working? If the answer is: I can't see the LED blink, then that's because the ontime is to small to see with the naked eye.

Does interrupt VectorNumber_Vtpm1ch0 void TPM1C0IRQ() work?

Do your I2C functions work at all? Did you test them?

Emm.. I tested it out by seeing the LED on and off. Basically i used a oscilloscope to see the waveform... and through that testing i know my IRQ handler is not working. Hence, i am wondering if any of you can help me... ))):


Yes, the TPM handler can work but not the IRQ handler.

Thanks, I missed that. No whitespace in the code and I looked right over it.

I'm not familiar with that particular chip, but it appears you are enabling your interrupts so...

You make mention of seeing the waveform. Are you looking at both the incoming waveform and on another trace watching the output pin driving/sinking the LED? That on/off time of the LED is extremely short!

Emm.. I tested it out by seeing the LED on and off.

As I mentioned, this won't do. It will go so insanely fast that you would even have a hard time seeing it on scope.

Now I don't know what your LED_on and LED_off functions do exactly, but how about replacing the both with a toggle_led function:

OUTPIN ~= OUTPIN;

So when you touch the sensor the led will go 'on', when you touch it again it'll go 'off'. Time enough to get some scope-output.

Off course, I'm not taking contact bouncing into consideration.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.