µC LED toggeln mit Timer funktioniert nicht, warum?

Gast #2434996
Lesenswert?

Hallo zusammen!
mein folgendes µC Programm woll einfach nicht funktionieren, wo liegt 
mein fehler?

ich will ein LED , das an P1.0 hängt mit hilfe eines timer interrupts 
toggeln.

mfg tom


//author: Thomas Thurner

#include <msp430f2012.h>
#include "intrinsics.h"


unsigned int c1,c2,c3,c4,c5,start;

void config_clock(void);
void config_io(void);
void config_timerA2(void);
void init(void);



void config_clock(void)
{
  if (CALBC1_16MHZ ==0xFF || CALDCO_16MHZ == 0xFF) //test if information 
memory (EEPROM) has stored calibration data
  {
     while(1);                       // TRAP, stay in loop
  }

  BCSCTL1 = XT2OFF + CALBC1_16MHZ;     // set range to 16MHz

  DCOCTL = CALDCO_16MHZ;              // set DCO step + modulation to 
1MHz
  BCSCTL2 = SELM_0 + DIVM_0 + DIVS_3;           // MCLK = DCO/1 and 
SMCLK = DCO/1
  //BCSCTL3 = LFXT1S_2;                         // LFXT1 = VLO ONLY at 
MSP430x21x1 devices (!)
  IFG1 &= ~OFIFG;                               // Clear OSCFault flag
}

void config_timerA2(void)
{
  CCTL0 = CCIE;                                 // CCR0 interrupt 
enabled
  TACTL = TASSEL_1 + MC_1;                      // MCLK, upmode
  TACCR0 = 0x2F;                               // init value for timer 
periode
}

void config_io(void)
 {
  P1DIR = ~0x0C;
  P1OUT = 0x0C;
  P1SEL = 0x00;
  P1REN = 0x08;

  P1IE  = 0x0C;               // enable interrupts at port P1.3
  P1IES = 0x0C;               // P1.0 interrupt if HI-to-LO edge 
detected
  P1IFG = 0x00;               // clear all P1 interrupt flags

 }

void init(void)
{
start=0;
c1=0;
c2=0;
c3=0;
c4=0;
c5=0;
}


// MAIN 
************************************************************************
void main( void )
{
  WDTCTL = WDTPW + WDTHOLD;  // Stop watchdog timer to prevent time out 
reset
  config_clock();
  config_timerA2();
  config_io();
  init();

  __enable_interrupt();

while(1)
{

}
}

// MAIN END 
********************************************************************



// Timer_A2 interrupt service routine *******************
#pragma vector=TIMERA0_VECTOR
__interrupt void timer_A(void)
{
  c1++;
  if(c1>=16000)
  {
    c2++;
    c1=0;
  }
  if(c2>=21)
  {
    P1OUT^=0x01;
    c2=0;
  }


}

// PORT1 interrupt service routine *******************
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{

}
Gast #2435044
Lesenswert?

Ich kenn mich zwar mit den MSP430 nicht so gut aus, aber dieser Teil:
1
void config_clock(void)
2
{
3
 //test if information memory (EEPROM) has stored calibration data
4
  if (CALBC1_16MHZ ==0xFF || CALDCO_16MHZ == 0xFF) {
5
     while(1);                       // TRAP, stay in loop
6
  }
7
  ...
8
}
Wird endlos hängen bleiben, sobald die Bedingung erfüllt ist. Und da du 
in
1
void main( void ){
2
  WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer to prevent time out
3
reset
4
  config_clock();
5
  config_timerA2();
6
  config_io();
7
  init();
8

9
  __enable_interrupt();
10

11
  while(1){
12
  }
13
}
Den WDT disabled hast und die interrupts erst nach dem Aufruf der 
Funktion enableds, sehe ich nicht, wie man aus dieser Schleife wieder 
rauskommen kann.
Gast #2435053
Lesenswert?

ich hab jetzt die interrupts direkt danach wieder eingeschalten, 
funktioniert aber trotzdem nicht..

void main( void )
{

  WDTCTL = WDTPW + WDTHOLD;  // Stop watchdog timer to prevent time out 
reset

  __enable_interrupt();

  config_clock();
  config_timerA2();
  config_io();
  init();


while(1)
{

  if(start==1)P1OUT|=0x01;
}
}

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren