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.

Please let me know what is missing in this code....

Other Parts Discussed in Thread: MSP430F2491

Hi I don't need a new code to UART . But please let me know what is missing in the following code. I was testing it in proteus. I am at a very starting level in MSP430. Please help me...


#include "msp430f2491.h"
void uart_set();
int main( void )
{
  // Stop watchdog timer to prevent time out reset
  WDTCTL = WDTPW + WDTHOLD;
  uart_set();
  while(1)
  {
    UCA0TXBUF = 'A';
    while(!(IFG2 & UCA0TXIFG));
  return 0;
}
}
void uart_set()
{
   UCA0CTL1 = 0X71;// ACLK USED,ALL CHARACTERS RECEIVED
  P3SEL = 0X30; // P3.4 AND 3.5 USED FOR SPECIAL FUNCTION REGISTERS
  P3DIR = 0X10; // P3.4 TX GIVEN AS OUTPUT
  BCSCTL1 = 0XC0;//XT2 OFF, HIGH FREQUENCY MODE SELECTED, WITH 00 DIVIDER
  //BCSCTL2 = 0X00;//DCO FOR MCLK
  BCSCTL3 = 0X24;//3- to 16-MHz crystal or resonator WITH PF INTERNAL CAPACITANCE
  UCA0CTL0 =0;// parity disbled, lsb first, one stop bit, 8 character bits, uart mode with a software reset.
  UCA0BR0 =0XA0;// baud rate setting for 4MHz ,
  UCA0BR1= 0X01;
  UCA0MCTL =0X0D;//UC0BRX = 416,UCBRSX=6,UCBRFX =0 AS PER DATA SHEET
  UCA0CTL1 &=~0X01;//INITIALIZE UART
}

  • Before someone has to dig through every line of code trying to figure it out, you could tell us what the problem you are having is. Also, what you have done to debug/troubleshoot it. Be specific.
  • I am sorry my post was a poor one. All I wanted to do is transmit a single character 'A' through UART. I have selected ACLK which is by default sourced from LFXT1 crystal. I did necessary modifications in the Basic clock module and UART. All I want to know is the order I should do it i.e, what should come first. I have changed the ACLK value to 4MHz in proteus which I actually want to use. please guide me through the correct sequence..

  • Hi everyone.... I finally figured it out what is wrong with this code. It is the location of the return statement in the main function. I think it has to be out of the infinite loop. I am thankful to this silly mistake because, this made me do a lot of research on MSP430. I also found out it is always good to use CRO to observe the bits at TXD. I am not observing the 'A' at the terminal though. I can observe the pattern in the CRO. If any more changes are there for the correct baud rate, Please let me know.

  • and the problem to the Baud rate is the UCOS16 bit which is high and has to be low.
  • You're right with both observations.
    It is undefined 8Depends on compiler) what will happen when you exit the main function. There is no OS to return to. Likely, the MSP will be sent into power-down. On 2x family, this means the clocks are switched off, and the USCI will have no clock to send the data out. (writing to TXBUF only starts the transfer, it doesn't stop the CPU until the transfer is done, and once the transfer has started, TXBUF is 'empty' again, and TXIFG is set, so your code continues past the while loop).
    Also, your clock system configuration is strange.
    You set XTS, which means XT1 in high-frequency mode. And 3-16MHz range. However, in high-frequency mode, the internal capacitors cannot be used and need to be switched off (BCSCTL3=0x20). External caps are mandatory in HF mode.
    And yes, if you set UCOS16 (which you did), this adds an additional /16 divider and therefore UCBR = (416/16)=26. Or leave it clear.
  • Thank you very much for giving additional details than what I have actually understood.

**Attention** This is a public forum