This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

PC getting lost

Other Parts Discussed in Thread: MSP430F5309

Hello,

I seem to be having an issue where the PC gets lost after some time.  I am using the MSP430F5309, running the system clock using DCO ~= 8 MHz, and ACLK = 32768 Hz.  Approximately every 5 ms, I send data out via UART.  I am probing the UART_TX line via an oscilloscope while running IAR, and it seems that after several seconds, the MSP430 stops transmitting data via UART.  When I temporarily pause the program in IAR, it shows that the PC went somewhere it shouldn't have (an empty register).  I am not sure exactly what could be causing the issue, and was hoping that someone could lead me in the right direction.  Thanks in advance.

Code:

#include <msp430f5309.h>

volatile static unsigned char Send_Sensor_Values = 1;
volatile static unsigned int Sample_Period = 164;
volatile static unsigned char Read_Sens_Flag = 0;
void sendBYTE(char val);

void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
UCSCTL3 = SELREF_2; // Set DCO FLL reference = REFO
UCSCTL4 |= SELA_2; // Set ACLK = REFO
UCSCTL0 = 0x0000; // Set lowest possible DCOx, MODx

// Loop until XT1,XT2 & DCO stabilizes - In this case only DCO has to stabilize
do
{
UCSCTL7 &= ~(XT2OFFG + XT1LFOFFG + DCOFFG);
// Clear XT2,XT1,DCO fault flags
SFRIFG1 &= ~OFIFG; // Clear fault flags
}while (SFRIFG1&OFIFG); // Test oscillator fault flag

__bis_SR_register(SCG0); // Disable the FLL control loop
UCSCTL1 = DCORSEL_5; // Select DCO range 16MHz operation
UCSCTL2 |= 249; // Set DCO Multiplier for 8MHz
// (N + 1) * FLLRef = Fdco
// (249 + 1) * 32768 = 8MHz
__bic_SR_register(SCG0); // Enable the FLL control loop

// Worst-case settling time for the DCO when the DCO range bits have been
// changed is n x 32 x 32 x f_MCLK / f_FLL_reference. See UCS chapter in 5xx
// UG for optimization.
// 32 x 32 x 8 MHz / 32,768 Hz = 250000 = MCLK cycles for DCO to settle
__delay_cycles(250000);

/* Start UART Setup */
P4SEL |= BIT4+BIT5; // P4.4,5 = USCI_A1 TXD/RXD
UCA1CTL1 |= UCSWRST; // **Put state machine in reset**
UCA1CTL1 |= UCSSEL_2; // SMCLK
UCA1BR0 = 72; // 8MHz 115200 (see User's Guide)
UCA1BR1 = 0; // 8MHz 115200
UCA0MCTL |= UCBRS_7 + UCBRF_0; // Modulation UCBRSx=7, UCBRFx=0
UCA1CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
/* End UART Setup */

TA0CCTL0 = CCIE; // CCR0 interrupt enabled
TA0CCR0 = 100;
TA0CTL = TASSEL_1 + MC_2 + TACLR + TAIE; // ACLK, Continuous Mode, clear TAR

P6DIR |= BIT1; // P6.1 output

__bis_SR_register(LPM0_bits + GIE);
while (1) {
if (Read_Sens_Flag) {
Read_Sens_Flag = 0;

P6OUT ^= BIT1;
if (Send_Sensor_Values) {
for (int i = 0; i < 6; i++) {
sendBYTE(97 + i);
}
}
}

if (Read_Sens_Flag == 0) {
__bis_SR_register(LPM0_bits + GIE);
}

}
}

// Timer0 A0 interrupt service routine
#pragma vector=TIMER0_A0_VECTOR
__interrupt void TIMER0_A0_ISR(void)
{
__bic_SR_register_on_exit(CPUOFF);
Read_Sens_Flag = 1;
TA0CCR0 += Sample_Period;
}

void sendBYTE(char val) {
while (!(UCA1IFG&UCTXIFG)); // USCI_A1 TX buffer ready?
UCA1TXBUF = val;
}

Sincerely,

Mehdi

PS: By the way, is there an easy way to insert code so that the indentation shows properly?

  • I do not know if this is similar to an issue i had where the PC stopped responding, I had to turn off the screen saver and any sleep modes.

    Right click on the desktop ( assuming windows here ) go to properties.  In new window, go to the screen saver tab, set to " none " for screen saver, click apply.  Then click the button at the bottom called "Power..." set each drop down to never then OK ( which will close the window ).  A similar issue I had was the hard drive would go to sleep mode ( in spite of me buffering incoming data ) and it would make it look like my project failed.

    Hope this simple solution is of help.

    Eric.

  • Hi Eric,

    Sorry I should have been more specific.  By PC I meant program counter (or instruction pointer).  Somehow my program seems to end up in an empty register and stays there.  This happens whether I run the code through IAR, or if i remove the debugger and run the microcontroller on its own.

    Thanks for the suggestion though.

    Mehdi

  • Mehdi Rahman said:
    TA0CTL = TASSEL_1 + MC_2 + TACLR + TAIE; // ACLK, Continuous Mode, clear TAR

    The comment is missing "enable timer overflow interrupt", as this is what TAIE does.

    So when the timer overflows, TIMER0_A1_VECTOR ISR is called, which you don't have, so the CPU fetches 0xffff as ISR address and jumps into the void.

    To enable the caputer/compare interrupts, it is not necessary to set TAIE. TAIE is an interrupt of its own.

    Mehdi Rahman said:
    PS: By the way, is there an easy way to insert code so that the indentation shows properly?

    No. There was an editor with highlighting, but only for a few days after the last big site update. It was removed.
    You may insert pre-formatted HTML code or paste from Word. Or you may switch the Font to Courier New (a non-proportional font). However, TABs are not show up as indentation anyway, they need to be turned into spaces.

  • Hi Jens-Michael Gross,

    Thank you very much!

    I originally had a larger code file, where I was using Timer0_A1.  However, I had temporarily commented that portion out but unfortunately left TAIE enabled, which was causing the PC to get lost.  I then simplified the code to what I showed above, and the PC still got lost.

    This clearly shows the importance of commenting code well from the get go.  Appreciate the help.

    Sincerely,

    Mehdi

  • Mehdi Rahman said:
    This clearly shows the importance of commenting code well from the get go.

    Too true. Missing or incorrect comments, or comments that haven't been updated when the code was changed, are a major annoyance and make debugging difficult. Even for the author himself, and even more for 3rd party.

    Often enough, code domments are stating the obvious ("increment counter") and miss the important things ("release attached slave from reset" or "use internal signal XY as trigger, that is not internally available on other devices"). Great for sample code.

**Attention** This is a public forum