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.

MSP430F5338 UART

Other Parts Discussed in Thread: MSP430F5338

Hello 

I am using MSP430F5338  UART OF USCI_A0. 

I have configure  Port 2 pins for TX and RX  using PORT mapping functions.

I  have used ACLK 32768hz.

I want to transmit only one byte on uart . But my code is not working .

UCSCTL4=SELA_2;                //SELECT REFOCLOCK 32768hz FOR ACLK

P2SEL |=BIT4+BIT5; //FOR PORT MAPPING FUNCTION;


PMAPKEYID=0X02D52; //ENABLE WRITE ACCESS TO PORT MAPPING REGISTERS;


if (!(PMAPCTL & PMAPLOCKED))
{
P2MAP4=PM_UCA0TXD;               //  P2.4  CONFIGURE FOR TX 
P2MAP5=PM_UCA0RXD;                //  P2.5 CONFIGURE FOR TX 
}


UCA0CTL1=UCSSEL_1; //ACLK CLK


UCA0BR0=0X03; // FOR BAUD RATE 9600
UCA0BR1=0X00;


UCA0MCTL=0X4A; //MULTIPLICATION FACTOR 4A

UCA0IE=UCTXIE+UCRXIE; //ENABLE INTERRUPTS


UCA0CTL1&=~UCSWRST; //CLEAR RST FOR UART OPERATION


while(!(UCA0IFG&UCTXIFG)); //CHECKING TRANSMIT FLAG


UCA0TXBUF=0xAB; //SENDING BYTE


while(!(UCA0IFG&UCTXIFG));

 Pls let me know where is the problem in this approch?

Manish 

 

  • In your code, you enable RX and TX interrupts. This means you tell the CPU to execute an ISR when the interrupt happens. Which only makes sense when you have ISRs for handling these events (but you don’t). However, setting the IS bits is futile because they are automatically reset as long as SWRST is set.
    Also, you did not set GIE to globally enable the interrupt mechanism.
    TXIFG and RXIFG are sent independently of the TXIE/RXIE bits – they just don’t cause any interrupt if the IE bits are not set.

     UCAxMCTL is not a multiplication factor, but a modulation pattern. Since 32768/9600 = 3.4133 and a bit can only have an integer multiple of the clock, this pattern controls which bits are shorter (3, as you wrote UCA0BR) and which bits shall be longer (3+1), so that the average bit time is 3.4133 (or as close as this algorithm can come to it).

     At first glance, the code looks good. However, what doe sit do after the second while?
    The first while is superfluous. After clearing SWRST, TXIFG is always set immediately. After writing to TXBUF (when the USCI was previously idle), TXIFG is immediately set again as soon as the sending of the first byte has begun (the next clock pulse arrived). So the second while is exited before even the start bit of the first is transmitted. Depending on what the code does after the second while, ti may be that the system shuts down before anything goes out.

    You should add a while(1); at the end of main, or at least wait for UCBUSY to be clear (meaning that all pending bits have been sent) before you proceed (or exit main).

**Attention** This is a public forum