Jump to content
Sign in to follow this  
JMLB

timer interrupts not working

Recommended Posts

I am trying to get a timer interupt working. I have had it worked before, but then I left it out a bit and coming back to it, it is not working. I want to send data serially to my pc for now. I am now running the code that was provided in example and I put a break point in the interrupt function and it never breaks.

 

Any thoughts?

thanks

Share this post


Link to post
Share on other sites

u have to post some code, or points us to the example u are trying (from slac080h?)

 

possible cause:

 

. if u are running the circuit w/o launchpad, u need to tie the RESET pin to Vcc.

. example requiring u to install 32Khz crystal.

. typos in your code.

Share this post


Link to post
Share on other sites

I got the code form the example for the uart where it echo what it receives. I don't do a read though I just set the byte to A (65). MY break point does not get hit and nothing show up in my terminal (even in hex view) I have soldered the crystal too

I am also running on the launch pad

 

#define RXD       0x04                      // RXD on P1.2
#define TXD       0x2                      // TXD on P1.1

//   Conditions for 2400 Baud SW UART, ACLK = 32768

#define Bitime_5  0x06                      // ~ 0.5 bit length + small adjustment
#define Bitime    0x0E                      // 427us bit length ~ 2341 baud (clock / baudrate)

unsigned int RXTXData;
unsigned char BitCnt;

void TX_Byte (void);
void RX_Ready (void);

//  M. Buccini / L. Westlund
//  Texas Instruments Inc.
//  October 2005
//  Built with CCE Version: 3.2.0 and IAR Embedded Workbench Version: 3.40A
//******************************************************************************

#include  


void main (void)
{
 WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog timer
 CCTL0 = OUT;                              // TXD Idle as Mark
 TACTL = TASSEL_1 + MC_2;                  // ACLK, continuous mode
 P1SEL = TXD + RXD;                        //
 P1DIR = TXD;                              //

// Mainloop
 for (;
 {
RXTXData = 'A';
__bis_SR_register(GIE);
 TX_Byte();                                // TX Back RXed Byte Received
 }
}


// Function Transmits Character from RXTXData Buffer
void TX_Byte (void)
{
 BitCnt = 0xA;                             // Load Bit counter, 8data + ST/SP
 while (CCR0 != TAR)                       // Prevent async capture
   CCR0 = TAR;                             // Current state of TA counter
 CCR0 += Bitime;                           // Some time till first bit
 RXTXData |= 0x100;                        // Add mark stop bit to RXTXData
 RXTXData = RXTXData << 1;                 // Add space start bit
 CCTL0 =  CCIS0 + OUTMOD0 + CCIE;          // TXD = mark = idle
 while ( CCTL0 & CCIE );                   // Wait for TX completion
}


// Function Readies UART to Receive Character into RXTXData Buffer
void RX_Ready (void)
{
 BitCnt = 0x8;                             // Load Bit counter
 CCTL0 = SCS + OUTMOD0 + CM1 + CAP + CCIE;   // Sync, Neg Edge, Cap
}

// Timer A0 interrupt service routine
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A (void)
{
 CCR0 += Bitime;                           // Add Offset to CCR0

// TX
 if (CCTL0 & CCIS0)                        // TX on CCI0B?
 {
   if ( BitCnt == 0)
   CCTL0 &= ~ CCIE;                        // All bits TXed, disable interrupt
   else
   {
     CCTL0 |=  OUTMOD2;                    // TX Space
     if (RXTXData & 0x01)
     CCTL0 &= ~ OUTMOD2;                   // TX Mark
     RXTXData = RXTXData >> 1;
     BitCnt --;
   }
 }
// RX
 else
 {
   if( CCTL0 & CAP )                       // Capture mode = start bit edge
   {
   CCTL0 &= ~ CAP;                         // Switch from capture to compare mode
   CCR0 += Bitime_5;
   }
   else
   {
   RXTXData = RXTXData >> 1;
     if (CCTL0 & SCCI)                     // Get bit waiting in receive latch
     RXTXData |= 0x80;
     BitCnt --;                            // All bits RXed?
     if ( BitCnt == 0)
//>>>>>>>>>> Decode of Received Byte Here <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
     {
     CCTL0 &= ~ CCIE;                      // All bits RXed, disable interrupt
     _BIC_SR_IRQ(LPM3_bits);               // Clear LPM3 bits from 0(SR)
     }
//>>>>>>>>>> Decode of Received Byte Here <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
   }
 }
}

 

Thanks for your time

Share this post


Link to post
Share on other sites

i can see u are just sending...

and u relocate the pins to a better place.

 

#define RXD 0x04 // RXD on P1.2

#define TXD 0x2 // TXD on P1.1

 

i don't think u can just change TXD from P1.5 to P1.1 just like that

 

may be try also change (inside your transmit function)

from

CCTL0 = CCIS0 + OUTMOD0 + CCIE; // TXD = mark = idle

to

CCTL0 = CCIS1 + OUTMOD0 + CCIE; // TXD = mark = idle

 

not 100% sure though.

 

could also be you keep constantly sending stuff, may be give each byte a delay after send.

 

[EDIT]

sorry should say replace your CCIS0 to CCIS1, this is a "input select" parameter, i think it's also for "output select". replace all, they are in a few places

Share this post


Link to post
Share on other sites

I switched the pis to p1.1 and p1.2 because TXD and RSD is written on those pins in the launch pad. I tried the modifications you suggested but no luck. what does it do? I am also not sending bytes until the first one was sent because of this line

while ( CCTL0 & CCIE ); // Wait for TX completion

my code just loops at that line. the timer never gets called. Also I don't think its a pin config because my break point in my timer interrupt does not get hit. but my others do.

 

I have also tryied swiching the clock to

 BCSCTL1 = CALBC1_1MHZ;                    // Set range
 DCOCTL = CALDCO_1MHZ;

TACTL = TASSEL_2 + MC_3;

Share this post


Link to post
Share on other sites

sorry, my mistake, the CCIS0/1 would is for something else (when u use CCR1, not very sure).

 

are you using optimization flags for your compiler? if yes, you need to make sure these globals are not optimized out.

 

unsigned int RXTXData;

unsigned char BitCnt;

 

by changing them to

 

volatile unsigned int RXTXData;

volatile unsigned char BitCnt;

 

 

 

may be u load a quick example to confirm your crystal is good?

 

try also msp430x20x3_ta_04.c, just to make sure it's not the crystal causing trouble.

Share this post


Link to post
Share on other sites

if u switch the clock to try, u need to change the timing (as u are running at 1Mhz now)

 

#define BAUDRATE 2400

 

#define BIT_TIME (1000000 / BAUDRATE)

#define HALF_BIT_TIME (BIT_TIME / 2)

 

just in case u haven't done so.

Share this post


Link to post
Share on other sites

ok I got it go go in the interrupt I think its my Cristal I used it before but its not working now. I changed the clock to use the programmable one and it is now going in my interrupt using the code i posted earlier. I don;t know why I didn't see it working before but it is now. It is not showing anything in my terminal but that might be cause I don't have the right timing.

 

thanks for your help!

Share this post


Link to post
Share on other sites

well, we may have missed that u forgot to enable interrupt

 

_BIS_SR(GIE);

 

when u take away the LPM3 sleeping, that line was

 

_BIS_SR(LPM3_bits + GIE);

 

so u should put it before your for(/*ever*/) loop.

 

may be

Share this post


Link to post
Share on other sites

IT seems after switching the clock. I put it in up down mode (MC_3) and the interrupt got called. but if I put it in continuous mode MC_2 I seem to get stuck in this loop

I think its safe to remove since i am not doing a capture?

while (CCR0 != TAR) // Prevent async capture

CCR0 = TAR;

Share this post


Link to post
Share on other sites

I had __bis_SR_register(GIE); but I replaced it with _BIS_SR(GIE); and put in before the main loop but no luck.

 

I connected the TXD pin to a led pin and added a break point ever timer tic and saw the led go on and off properly so its sending it on the TXD pin but its probably bad time I think I need to deived the clock some more. lol I am missing some thing i think

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...