IIC Interrupt Handler

Reply

Join Date: Jul 2009
Posts: 3
Reputation: ngjinjin is an unknown quantity at this point 
Solved Threads: 0
ngjinjin ngjinjin is offline Offline
Newbie Poster

IIC Interrupt Handler

 
0
  #1
Jul 6th, 2009
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...
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,834
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 297
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is offline Offline
Roasting Maven

Re: IIC Interrupt Handler

 
0
  #2
Jul 6th, 2009
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
Last edited by niek_e; Jul 6th, 2009 at 6:50 am.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 3
Reputation: ngjinjin is an unknown quantity at this point 
Solved Threads: 0
ngjinjin ngjinjin is offline Offline
Newbie Poster

Re: IIC Interrupt Handler

 
0
  #3
Jul 6th, 2009
Originally Posted by niek_e View Post
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
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,834
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 297
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is offline Offline
Roasting Maven

Re: IIC Interrupt Handler

 
0
  #4
Jul 6th, 2009
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?
Last edited by niek_e; Jul 6th, 2009 at 7:28 am.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 830
Reputation: wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all 
Solved Threads: 94
wildgoose's Avatar
wildgoose wildgoose is offline Offline
Practically a Posting Shark

Re: IIC Interrupt Handler

 
0
  #5
Jul 6th, 2009
Put a counter on the interrupt and pre-clear, then after a short while, examine the counter and see if it is non zero!
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,834
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 297
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is offline Offline
Roasting Maven

Re: IIC Interrupt Handler

 
0
  #6
Jul 6th, 2009
Originally Posted by wildgoose View Post
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?
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 3
Reputation: ngjinjin is an unknown quantity at this point 
Solved Threads: 0
ngjinjin ngjinjin is offline Offline
Newbie Poster

Re: IIC Interrupt Handler

 
0
  #7
Jul 6th, 2009
Originally Posted by niek_e View Post
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.
Last edited by ngjinjin; Jul 6th, 2009 at 11:45 am.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 830
Reputation: wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all 
Solved Threads: 94
wildgoose's Avatar
wildgoose wildgoose is offline Offline
Practically a Posting Shark

Re: IIC Interrupt Handler

 
0
  #8
Jul 6th, 2009
Thanks, I missed that. No whitespace in the code and I looked right over it.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 830
Reputation: wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all 
Solved Threads: 94
wildgoose's Avatar
wildgoose wildgoose is offline Offline
Practically a Posting Shark

Re: IIC Interrupt Handler

 
0
  #9
Jul 6th, 2009
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!
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,834
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 297
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is offline Offline
Roasting Maven

Re: IIC Interrupt Handler

 
0
  #10
Jul 6th, 2009
Originally Posted by ngjinjin View Post
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:

  1. 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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC