here is my code i have two timer interrupts but both of them doesnt work please help me
#include <msp430g2553.h>#include <stdbool.h>#include <in430.h>#define pompa BIT6#define BUTTON BIT3int sicaklik=0;int second=0;int minute=0;int hour=0;int nem=0;int count=0;int sicaklikonlar;int sicaklikbirler;int nemyuzler;int nemonlar;int nembirler;int rs232gidenfonk;int rs232giden;bool rs232gonderilecek=0;int rs232bit=0;int temp();int humidity();int rs232gonder(int); void main(void){WDTCTL = WDTPW|WDTHOLD;P1DIR=0x22; P1OUT=0x02;TACCTL0=CCIE;TACCR0=0xFFFF;TACCTL0=TASSEL_2|ID_3|MC_3|TACLR;_enable_interrupt();for(;;){if(minute%2){sicaklik=temp();sicaklikonlar=sicaklik/10+48;sicaklikbirler=sicaklik%10+48; }if(count==1){nem=humidity();nemyuzler=nem/100;nemonlar=nem/10+48;nembirler=nem%10+48;} rs232gonder(nemyuzler); }}#pragma vector = TIMER0_A0_VECTOR __interrupt void TA0_ISR(void){second++;if(second>=60){ second=0; minute++; if(minute>=60){ minute=0; hour++; if(hour==6){ second=0; minute=0; hour=0; } } }}int temp(){int T;int temperature;ADC10CTL0 = SREF_1|ADC10SHT_3|REFON|ADC10ON;ADC10CTL1 = INCH_10|ADC10DIV_3;ADC10CTL0|=ENC|ADC10SC;temperature=ADC10MEM;T=((temperature - 673) * 423) / 1024;count=1;return T;}int humidity(){int b;int M;ADC10CTL0=SREF_1|ADC10SHT_3|REFON|ADC10ON;ADC10CTL1=INCH_0|ADC10DIV_3;ADC10CTL0|=ENC|ADC10SC;M = ADC10MEM*2500 /2^12;b = 11.9 * 10E-4 * M - 0.401;count=0;return b;}int rs232gonder(int rs232gidenfonk){ if(rs232gonderilecek==0) { rs232giden=rs232gidenfonk; rs232giden=rs232giden << 1; rs232giden+=512; rs232gonderilecek=1; TACCTL1=CCIE; TACCR0=108; TACCTL1=TASSEL_2|ID_0|MC_1|TACLR; _enable_interrupt(); } }#pragma vector = TIMER0_A1_VECTOR __interrupt void TA1_ISR (void){if(rs232gonderilecek==1){ if(rs232bit < 10) { P1OUT=rs232giden&BIT0; rs232giden=rs232giden>>1; } else { TACCTL1= MC_0; rs232gonderilecek=0; } } rs232bit++;}
Hi Arda,
I got both timers working. Try these - maybe something very small.
1. Please clear the IFG flag : TACCTL1 &= ~CCIFG; // clear interrupt register : in TA1 ISR.
2. Reload TACCR1 in the TA1 ISR before exiting.
3. During initialization load TACCR1 with a value and enable the TA1 Interrupt : TACCTL1 = CCIE;
Best Wishes,
Suresh
Arda Akalın TACCTL1= MC_0;
However, your code unintendedly dows the right thing: it clears BIT0 (CCIFG) from TACCTL1, which needs to be done for any tierm interrupt except CCR0 (which has its own vector and auto-clears on ISR start). But it also disables TACCR1 interrupt (clears CCIE bit) and so the TACCR1 interrupt is called only once.
TACCR0 interrupt is called frequently,
In RS232gonder() you do the same thing: TACCTL1 = TASSEL_2... which is wrong too. It should read TACTL=TASSEL_2...
However, stopping the timer and restarting/resetting it, means that you won't get your TACCR0 interrupt at regular intervals. I think there is a logical error in the base concept of your code.
Anothe rone: every variable that is use din both, main code and interrupt code, should be declared volatile to tell the compiler that it may change 'magically' during main code execution or may be required to be written immediately. Else code optimization may lead to changes being ignored until next function return.
_____________________________________Before posting bug reports or ask for help, do at least quick scan over this article. It applies to any kind of problem reporting. On any forum. And/or look here.If you cannot discuss your problem in the public, feel free to start a private conversation: click on my name and then 'start conversation'. But please do so only if you really cannot do it in a public thread, as I usually read all threads. And I prefer to answer where others can profit from it (or contribute to it) too.