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.

CCS/MSP430F6435: Code stuck in Interrupt flag, UCRXIFG

Part Number: MSP430F6435

Tool/software: Code Composer Studio

I am currently stuck at this UCRXIFG polling condition. The code gives +++ to a xbee and waits for the OK response from the device. I am using a different clock structure for my system, XT1 = 32K and XT2 = 32M. Is some setting wrong in the clock configuration because the UART calculations are correct to the best of my knowledge. Attaching my code for referral

#include <stdio.h>
#include <msp430.h>

void vGpio_Init(void)
{

        // Configure all GPIO to Output Low
        // Make sure there is no pin conflict with respect to schematic
        P1OUT = 0x00; P2OUT = 0x00; P3OUT = 0x00; P4OUT = 0x00;
        P5OUT = 0x00; P6OUT = 0x00; P7OUT = 0x00; P8OUT = 0x00;
        P9OUT = 0xFF;

        P1DIR = 0xFF; P2DIR = 0xFF; P3DIR = 0xFF; P4DIR = 0xFF;
        P5DIR = 0xFF; P6DIR = 0xFF; P7DIR = 0xFF; P8DIR = 0xFF;
        P9DIR = 0xFF;

}

void vMspclock_init(void)
{
    //-----------
    //General Settings
    P7SEL |= BIT2+BIT3;                       // Port select XT2

    UCSCTL6 &= ~XT1OFF;                         // Enable XT1 for RTC_B
    UCSCTL6 |= XCAP_3 | XT1BYPASS;             //Internal load cap 12pF configuration
    UCSCTL6 &= ~XT2OFF;                        // Enable XT2 for MCLK, SMCLK, ACLK
    UCSCTL3 |= SELREF_2;                       // Reference to FLL is given from XT2
    UCSCTL6 |= XT2DRIVE_3;                      //Selecting high current drive capacity and current consumption for 32 MHz crystal
    //UCSCTL7                                   //This register is used to check oscillator fault flag, ie if there  is some error in the osc due to supply conditions

    //Init MCLK
    UCSCTL4 |= SELM_5;                         //Uses XT2(32MHz) crystal oscillator source
    UCSCTL5 |= DIVM_3;                          //Divides the clock source by 32, ie. 32/1 = 32Khz

    //Init SMCLK
    UCSCTL4 |= SELS_5;                         ////Uses XT2(32MHz) crystal oscillator source
    UCSCTL5 |= DIVS_0;                          //Divides the clock source by 1, ie. 32/1 = 32Khz

    //Init ACLK
    UCSCTL4 |= SELA_5;                         ////Uses XT2(32MHz) crystal oscillator source
    UCSCTL5 |= DIVA_3;                          //Divides the clock source by 8, ie. 32/8 = 4Khz
    //UCSCTL5 |= DIVPA_3;                          //This can divide the ACLK source available at external pin by any value like previous line

    do
    {
      UCSCTL7 &= ~(XT2OFFG + XT1LFOFFG + XT1HFOFFG + DCOFFG);
                                              // Clear XT2,XT1,DCO fault flags
      SFRIFG1 &= ~OFIFG;                      // Clear fault flags
    }while (SFRIFG1&OFIFG);                   // Test oscillator fault flag
}

void vUART_INIT(void)
{
    P8SEL |= 0x04;                      //For TX pin
    P8DIR |= 0x04;

    P8SEL |= 0x08;                      //For RX pin

    UCA1CTL1 |= UCSWRST;                //Essential to set this bit as all the registers are configurable only when UCSWRST = 1

    UCA1CTL1 |= UCSSEL__SMCLK;          //CAN also be written as UCA0CTL1 |= UCSSEL_1;//to SELECT THE CLOCK SOURCE OF THE UART communication
                                        //For reference of calculation - processors.wiki.ti.com/.../USCI_UART_Baud_Rate_Gen_Mode_Selection
    UCA1BR0 = 0x52;                     //These 2 registers represent the calculation for the baud rate according to the frequency of the clock
    UCA1BR1 = 0x00;                     //32000000/16*(1/38400)=52, so lsb = 52 and msb =0
    UCA1MCTL = UCOS16 | UCBRF_1;        //first setting sets the oversampling mode, second bit is the calculation for the UCBRF
    //UCA1MCTL = UCBRS_2;
    UCA1CTLW0 &= ~UCSWRST;              //Clearing the register to start the UART configuration
}


/**
 * hello.c
 */
int main(void)
{
	WDTCTL = WDTPW | WDTHOLD;	// stop watchdog timer
    char send_init[3]={'+','+','+'};
    int i; char rxbit;

    vGpio_Init();
    vMspclock_init();
    vUART_INIT();

    for(i=0;i<3;i++)
    {
        while(!(UCA1IFG & UCTXIFG));        //Poll for transmit interrupt flag
        UCA1TXBUF = send_init[i];           // Transmit data
        UCA1IFG &=~(UCTXIFG);
    }

    for(i=0;i<10000;i++);       //waiting for the ok responce

    for(i=0;i<3;i++)
    {
        while(!(UCA1IFG & UCRXIFG));        //Poll for transmit interrupt flag----CODE STUCK HERE
        rxbit = UCA1RXBUF;
        UCA1IFG &=~(UCRXIFG);
        printf("%d ", rxbit);
    }

	printf("Hello World!\n");

	return 0;
}

I am a newbie and any help would be appriciable

Onkar

  • Hi Onkar!

    for(i=0;i<3;i++)
    {
        while(!(UCA1IFG & UCTXIFG));        //Poll for transmit interrupt flag
        UCA1TXBUF = send_init[i];           // Transmit data
        UCA1IFG &=~(UCTXIFG);
    }
    
    for(i=0;i<10000;i++);       //waiting for the ok responce
    
    for(i=0;i<3;i++)
    {
        while(!(UCA1IFG & UCRXIFG));        //Poll for transmit interrupt flag----CODE STUCK HERE
        rxbit = UCA1RXBUF;
        UCA1IFG &=~(UCRXIFG);
        printf("%d ", rxbit);
    }

    You are sending three bytes to the slave, then you are waiting in a loop for a response and then you want to receive three chatracters - this will not work. The RX buffer holds one single byte. I guess while you are waiting in the second for-loop, the slave already sent it's three bytes, the second overwrites the first and the third overwrites the second. I could imagine that your printf outputs one character and after that your last for-loop runs forever. (Assuming your communication settings are correct)

    Dennis

  • Thank you Dennis
    Commented out the second for loop, but still no change. Now the code is stuck at the line

    while(!(UCA1IFG & UCRXIFG));
    hence the code never reaches the printf statement

    Onkar
  • So then RXIFG does not get set. Did you try if it gets set if you connect TX and RX? If so, the UART seems to work in general but maybe your configuration is wrong. This could mean that the slave does not receive anything useful and therefore does not send something back at all.

  • Thanx Dennis

    My analysis goes as follows . . .

    Slave is working fine when checked with dedicated software. UART setting are simple and small and there is just the calculation part(which was crosschecked by the calculation generator online). Hardware is the same over which it worked a couple of months ago. The clock function is the suspicious one as I am working with such configuration for the first time.

    Still can't figure it out.
  • 
    

    > UCA1IFG &=~(UCTXIFG);

    > UCA1IFG &=~(UCRXIFG);
    Remove these lines. Reading/writing RXBUF/TXBUF already clears the relevant IFG. Doing it (again) explicitly introduces races which can cause hangs or lost data. If you haven't seen these yet, you will eventually.

    That said, the symptoms I would expect don't match well with your stated symptoms. Are you certain that printf() is Never called? (Try a breakpoint.) Where does the printf() output go?

    I have this vague recollection that "+++" requires guard bands (delays) between the characters in order to be recognized. You may want to check the Book for the XBee for any requirements like this.

  • Thankx Bruce

    Yes, the printf never gets called, code never reaches that line. Also tried delay between the charecters in the +++. Still no good. :/

    Onkar

**Attention** This is a public forum