Other Parts Discussed in Thread: MSP430F5529,
OK - and trying to run an interrupt on the Timer B CC0 channel, so when TBxR wraps. I've stripped down my code to a simple test program, that is designed to have the interrupt just flash the LED. So question is what have I missed.
The only slightly unusual thing in my code, is rather than the usual hidden function to write registers, I've just done a direct write to the memory mapped address of the register. Sh ould be able to read my code though because I should have kep standard names
#include <msp430.h> #include <stdint.h> #include "timerb.h" volatile uint32_t count=0; int main(void) { // Stop WDT HWREGW( WDT_A_BASE | WDTCTL ) = WDTPW|WDTHOLD; // Now set up Timer B // note do this with "+" rather than "|" as TBxEX0 is too far out! // first disable before programming HWREGW( TIMER_B0_BASE + TBxCTL )&=0xffcf; // all Timer B latch updates not tied together (But // 16 bit // SMCLK is the clock // divide by 1 // keep disabled // Time clear - here we clear just be sure, but will do again when start // TBIFG interrupt disabled (we just do CC0) // and set TBIDEX to divide by 1 as well HWREGW( TIMER_B0_BASE + TBxCTL )= TBCLGRP_0 | CNTL__16 | TBSSEL__SMCLK | TBCLR ; HWREGW( TIMER_B0_BASE + TBxEX0 )= TAIDEX_0; // latch when TB0R counts to zero - and CCR0 sets period // and CCR0 is the interupt HWREGW( TIMER_B0_BASE + TBxCCTL0 )= CLLD_1 | CCIE; HWREGW( TIMER_B0_BASE + TBxCCR0 )= Period-1; // Now all set enable and clear HWREGW( TIMER_B0_BASE + TBxCTL )= MC__UP | TBCLR ; // and set the LED so we can write to it HWREGB( P1_BASE | PxDIR ) |= BIT0; // now all set for now just loop, with LED flashing while(1) { // HWREGB( P1_BASE | PxOUT ) ^= BIT0; for(uint16_t i=65535;i>0;i--); } } // TIMER B CC __attribute__((interrupt(TIMER0_B0_VECTOR))) void TIMER0_B0_ISR (void) { if ( (count++)%100000 == 0) HWREGB( P1_BASE | PxOUT ) ^= BIT0; }
and in case you need the header file its:
#include <stdint.h> #define HWREGB(x) (*((volatile uint8_t *)(x))) #define HWREGW(x) (*((volatile uint16_t *)(x))) #define HWREGQ(x) (*((volatile uint32_t *)(x))) // clocks to PWM cycle, and hence interupt in clocks #define Period 1000 #define PxIN 0x00 #define PxOUT 0x02 #define PxDIR 0x04 #define PxREN 0x06 #define PxDS 0x08 #define PxSEL 0x0a #define PxIES 0x18 #define PxIE 0x1a #define PxIFG 0x1c #define PxIV 0x0e #define PxSEL 0x0a // this is the whole wtdctl address as coun't find the 0xc offset documented #define WDTCTL 0x0c // UCS #define UCSCTL0 0x00 #define UCSCTL1 0x02 #define UCSCTL2 0x04 #define UCSCTL3 0x06 #define UCSCTL4 0x08 #define UCSCTL5 0x0a #define UCSCTL6 0x0c #define UCSCTL7 0x0e // SFR #define SFRIFG1 0x02 // Timer B #define TBxCTL 0x00 #define TBxCCTL0 0x02 #define TBxCCTL1 0x04 #define TBxCCTL2 0x06 #define TBxCCTL3 0x08 #define TBxCCTL4 0x0a #define TBxCCTL5 0x0c #define TBxCCTL6 0x0e #define TBxR 0x10 #define TBxCCR0 0x12 #define TBxCCR1 0x14 #define TBxCCR2 0x16 #define TBxCCR3 0x18 #define TBxCCR4 0x1a #define TBxCCR5 0x1c #define TBxCCR6 0x1e #define TBxIV 0x2e #define TBxEX0 0x20