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?