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.

trying to understand UART interrupt / initialization

Other Parts Discussed in Thread: MSP430G2955

Hi, 

I am trying to initialize the UART after which I am continously getting interrupt , By the way I am using MSP430G2955 so I did check if I am missing something in errata. 

I felt if there is an another set of eyeball looking at this part, it could be an easy hit on what I might be missing or doing wrong. I am trying to initialize as below. Is it that I need to clear the interrupt once to avoid being in the interrupt loop. 

void Ser_Init(void)
{
	DISABLE_SERIAL_INT;														

	UCA0BR0 = UBRR0_SETTING_FT12_1; // 1MHz 19200
	UCA0BR1 = UBRR0_SETTING_FT12_2; // 1MHz 19200
	UCA0MCTL = UBRRO_SETTING_FT12_3; //Modulation setting

	UCA0CTL0 &= ~(UC7BIT + UCSPB);// Set frame format: 8data, 1stop bit
	UCA0CTL0 |= UCPAR + UCPEN;// Set even parity

	UCA0CTL1 |= UCSSEL_2; // SMCLK
	UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**//Enabling receiver and transmitter

	ENABLE_SERIAL_INT;														
}



#pragma vector=USCIAB0TX_VECTOR
__interrupt void USCI0TX_ISR(void)
{
	CallStatemachine();
}

  • UCSWRST should be set for the configuration. (But it's set by default.)

    The TX interrupt is raised when the TX buffer is empty, i.e., when the UART can accept another by to send.

  • Hi Kewal!

    As soon as you enable the interrupt for TX and the global interrupts are enabled as well, the interrupt service routine is called. The flag is cleared when the TX buffer is filled. If you do not write something to the TX buffer in the ISR, the flag stays set and the ISR is called over and over again. Or you clear the flag manually, which is also possible. Keep in mind, that from the start of the program, the flag is set. If you put a byte into the TX buffer, the flag gets cleared, but the byte is immediately forwarded to the transmit shift register and the TX buffer is empty again, ready for the next byte which means the flag is immediately set again. Putting a second byte into the TX buffer clears the flag until the first byte was transmitted and the second byte is moved from the TX buffer to the shift register.

    Dennis
  • Clemens,

    I was able to understand with your explanation.

    So, Are you suggesting me to clear the interrupt manually along with the initialization. Typically I was expecting an interrupt after the written byte has been sent so is there any other flags or interrupts which I must be using.


    #define ENABLE_SERIAL_INT UC0IE |= UCA0RXIE | UCA0TXIE
    #define DISABLE_SERIAL_INT UC0IE &= ~(UCA0RXIE | UCA0TXIE)

    #define CLEAR_TR_INT IFG1 |= UCA0TXIFG

    void Ser_Init(void)
    {
    DISABLE_SERIAL_INT;

    UCA0BR0 = UBRR0_SETTING_FT12_1; // 1MHz 19200
    UCA0BR1 = UBRR0_SETTING_FT12_2; // 1MHz 19200
    UCA0MCTL = UBRRO_SETTING_FT12_3; //Modulation setting

    UCA0CTL0 &= ~(UC7BIT + UCSPB);// Set frame format: 8data, 1stop bit
    UCA0CTL0 |= UCPAR + UCPEN;// Set even parity

    UCA0CTL1 |= UCSSEL_2; // SMCLK
    UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**//Enabling receiver and transmitter

    ENABLE_SERIAL_INT;
    CLEAR_TR_INT;
    }
  • I was expecting an interrupt after the written byte has been sent

    But this is not what you get, so you cannot construct your state machine for this.

    You get an interrupt when the hardware is ready for the next (or first) byte to be sent.
    Why don't you write your state machine so that it works correctly with the first interrupt?

**Attention** This is a public forum