Other Parts Discussed in Thread: MSP430FR5739
First of all, I'm new to MSP430 but have experiences with several other µC.
I have a MSP430FR5739 and tried to experience with some interrupts etc. Because I didn't notice any occurance of timer interrupts, I tried to route the clock signals to pins PJ.0, PJ.1 and PJ.2.
int main(void) {
// Watchdog Timer anhalten
WDT_A_hold(WDT_A_BASE); // Stop watchdog timer
initTimings();
while (1) {
// LPM0 mit Interrupts
__bis_SR_register(LPM0_bits | GIE);
__no_operation();
}
}
/*
* Initialisierung von Clocks und Timern
*/
void initTimings() {
// DCO-Frequenz auf 8 MHz
CS_setDCOFreq(CS_DCORSEL_0, CS_DCOFSEL_3);
// MCLK: nutzt DCOCLK ( 8 MHz, Teiler 1)
// SMCLK: nutzt DCOCLK ( 1 MHz, Teiler 8)
// ACLK = SMCLK
CS_clockSignalInit(CS_ACLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_8);
CS_clockSignalInit(CS_MCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1);
CS_clockSignalInit(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_8);
GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_PJ, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2, GPIO_PRIMARY_MODULE_FUNCTION);
}
On the oscilloscope the clock signals appeared fine on the corresponding pins. But what happened after a minute or so? They disappeared! Why???
Then I tried to toggle an LED by a Timer A interrupt.
int main(void) {
// uint8_t cmd;
// Watchdog Timer anhalten
WDT_A_hold(WDT_A_BASE); // Stop watchdog timer
// Initialisierungen durchführen
initTimings();
GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN2);
GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN2);
// Endlos-Schleife
while (1) {
// LPM0 mit Interrupts
__bis_SR_register(LPM0_bits | GIE);
__no_operation();
}
}
/*
* Initialisierung von Clocks und Timern
*/
void initTimings() {
// DCO-Frequenz auf 8 MHz
CS_setDCOFreq(CS_DCORSEL_0, CS_DCOFSEL_3);
// MCLK: nutzt DCOCLK ( 8 MHz, Teiler 1)
// SMCLK: nutzt DCOCLK ( 1 MHz, Teiler 8)
// ACLK = SMCLK
CS_clockSignalInit(CS_ACLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_8);
CS_clockSignalInit(CS_MCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1);
CS_clockSignalInit(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_8);
// Timer A1 arbeitet im Continuous Mode bei 25 kHz
TIMER_A_clearTimerInterruptFlag(TIMER_A1_BASE);
TIMER_A_configureContinuousMode(TIMER_A1_BASE,
TIMER_A_CLOCKSOURCE_ACLK,
TIMER_A_CLOCKSOURCE_DIVIDER_40,
TIMER_A_TAIE_INTERRUPT_ENABLE,
TIMER_A_DO_CLEAR
);
TIMER_A_enableInterrupt(TIMER_A1_BASE);
TIMER_A_startCounter(TIMER_A1_BASE,
TIMER_A_CONTINUOUS_MODE
);
}
#define TA_CNT 25000
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=TIMER1_A1_VECTOR
__interrupt
#elif defined(__GNUC__)
__attribute__((interrupt(TIMER1_A1_VECTOR)))
#endif
void TIMER1_A1_ISR(void)
{
static volatile uint16_t usTimerACntr = TA_CNT;
switch ( __even_in_range(TA1IV, 14) ) {
case 0: break; // No interrupt
case 2: break; // CCR1 not used
case 4: break; // CCR2 not used
case 6: break; // CCR3 not used
case 8: break; // CCR4 not used
case 10: break; // CCR5 not used
case 12: break; // CCR6 not used
case 14: // Overflow
usTimerACntr--;
if (usTimerACntr == 0) {
swUptime++;
usTimerACntr = TA_CNT;
GPIO_toggleOutputOnPin(GPIO_PORT_P2, GPIO_PIN2);
}
break;
default: break;
}
// with and without the following command
TIMER_A_clearTimerInterruptFlag(TIMER_A1_BASE);
}
#undef TA_CNT
On startup the LED got lit and after some 25 seconds it turned off and never turned on again! I assumed and expected the following:
DCOCLK = 8 MHz, MCLK = 8 MHz, SMCLK = 1 MHz, ACLK = 1MHz
Timerinterrupt-Frequency: 1 MHz / 40 = 25 kHz, so a counter decrementing from 25000 should reach 0 every second. But it took that long long time. And no matter what value I changed in any way, the time doesn't get shorter...
Please help me! Any hint is appreciated.
Regards Helmut