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.

uart UCA0TXIFG never sets

Hello everyone,

 

I have a problem with this code, wich I have modified due

to understand how the Tx interrupt works on serial communication.

 

//******************************************************************************
//   MSP430F21x2 Demo - USCI_A0, UART 9600 Full-Duplex Transceiver, 32kHz ACLK
//
//   A. Dannenberg
//   Texas Instruments Inc.
//   April 2006
//   Built with CCE Version: 3.2.0 and IAR Embedded Workbench Version: 3.41A
//******************************************************************************
#include "msp430x21x2.h"

void main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog timer
  P1OUT = 0x00;                             // P1.0/1 setup for LED output
  //P1DIR = 0x03;
  P3SEL = 0x30;                             // P3.4,5 = USCI_A0 TXD/RXD
  UCA0CTL1 |= UCSSEL_1;                     // CLK = ACLK
  UCA0BR0 = 0x03;                           // 32kHz/9600 = 3.41
  UCA0BR1 = 0x00;
  UCA0MCTL = UCBRS1 + UCBRS0;               // Modulation UCBRSx = 3
  UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
  IFG2 &= ~(UCA0TXIFG+UCA0RXIFG);
  IE2 |= UCA0RXIE + UCA0TXIE;               // Enable USCI_A0 TX/RX interrupt

  __enable_interrupt();   
  //__bis_SR_register(LPM3_bits + GIE);       // Enter LPM3 w/ interrupts enabled
  while(1);
}

// USCI A0/B0 Transmit ISR
#pragma vector=USCIAB0TX_VECTOR
__interrupt void USCI0TX_ISR(void)
{
  UCA0TXBUF = 'a';           // Read, justify, and transmit
  IFG2 &= ~UCA0TXIFG;
}

// USCI A0/B0 Receive ISR
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
  __no_operation();                       
}

 

The problem is that UCA0TXIFG bit never sets to "1" during program execution, but as I have understand from userguide

this bit serve to know when the serial is ready to transmit another character.

In this example, wich is pretty useless code,  during debug the program may send continuosly character "a"

within serial com, but it doesn't. I don't understand why.

Sorry for my bad english.

Thanks

Max

 

 

 

 

  • Hi,

    well, I think it is the output driver in the port structure that causes the issue. As far as I can see from your code the driver is disabled.

    Take a look into the MSP430F21x2 datasheet [slas578] in chapter "Port P3 Pin Schematic: P3.1 to P3.5, Input/Output With Schmitt Trigger" on page 61. There you find the output schematic of the port pin. Here you can see that the bit for the TX output has to be set in P3DIR register - this activates the output driver and then you will see the data shifted out of the according pin.

    So in the code above replace "  //P1DIR = 0x03;"    by   " P1DIR = BIT4;".

    Regards.

  • Massimo Pennazio said:
    In this example, wich is pretty useless code,  during debug the program may send continuosly character "a" within serial com, but it doesn't. I don't understand why.


    When writing the first 'a' into TXBUF, UCA0TXIFG gets cleared automatically. However, one ticl later, the content of TXBUF is moved into th eoutput shift register and TXIFG is set again. two or three MCLK cycles later you manually clear TXIFG. Which then stays clear forever, unless you manualla push something into TXBUF to re-trigger the mechanism, or set UCSWRST to reset the USCI.
    Remove the line that clears UCA0TXIFG and it should work.

    However, you set RXIE but never handle the RX case. So as soon as the MSP receives a byte, it will enter an endless loop that calls the RX ISR over and over again, since nobody is actually reading the byte from RXBUF or manually clearing the RXIFG bit.

     

**Attention** This is a public forum