| | |
IIC Interrupt Handler
![]() |
•
•
Join Date: Jul 2009
Posts: 3
Reputation:
Solved Threads: 0
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...
#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...
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
Also: What microcontroller is this? And post a link to it's datasheet, I'm too lazy to search for it myself
Last edited by niek_e; Jul 6th, 2009 at 6:50 am.
•
•
Join Date: Jul 2009
Posts: 3
Reputation:
Solved Threads: 0
•
•
•
•
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/senso...eet/MPR083.pdf
2.
http://www.freescale.com/files/micro...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
Do your I2C functions work at all? Did you test them?
Does
interrupt VectorNumber_Vtpm1ch0 void TPM1C0IRQ() work?Do your I2C functions work at all? Did you test them?
Last edited by niek_e; Jul 6th, 2009 at 7:28 am.
•
•
Join Date: Jul 2009
Posts: 3
Reputation:
Solved Threads: 0
•
•
•
•
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.
Doesinterrupt 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.
Last edited by ngjinjin; Jul 6th, 2009 at 11:45 am.
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!
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!
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:
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.
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:
C Syntax (Toggle Plain Text)
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.
Last edited by niek_e; Jul 6th, 2009 at 11:53 am.
![]() |
Similar Threads
- Hi Help me with Multilevel feedback scheduling (Java)
- What is the purpose of registers (C++)
- C + Assembler = something I can't solve (C)
- what does keybd_event() do???? (C)
Other Threads in the C Forum
- Previous Thread: How to Disable UNICODE in VC++ 2008
- Next Thread: Pointer Problem
| Thread Tools | Search this Thread |
adobe api array arrays binarysearch calculate char cm convert copyanyfile copypdffile cprogramme createcopyoffile createprocess() csyntax directory dynamic feet fflush file floatingpointvalidation fork forloop frequency getlasterror givemetehcodez global graphics gtkgcurlcompiling hacking hardware highest homework i/o inches incrementoperators intmain() iso kernel kilometer km linked linkedlist linux linuxsegmentationfault list locate logical_drives loopinsideloop. match matrix microsoft motherboard mqqueue mysql oddnumber odf open opendocumentformat opensource openwebfoundation owf pattern pdf performance pointer posix power probleminc program programming pyramidusingturboccodes read recursion recv recvblocked repetition research scanf scheduling segmentationfault send shape socketprograming socketprogramming stack standard strchr string suggestions systemcall test unix urboc user variable voidmain() wab win32api windows.h






