Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

UART in MSP430 comunication doesn't work properly

Status
Not open for further replies.

scorrpeio

Full Member level 5
Joined
Dec 26, 2006
Messages
286
Helped
10
Reputation
20
Reaction score
9
Trophy points
1,298
Activity points
3,496
UART in MSP430

Hello,

I am writing a UART code to communicate with PC.

Code:
#include  "msp430x23x0.h"

void main(void)
{

  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
  if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)                                     
  {  
    while(1);                               // If calibration constants erased
                                            // do not load, trap CPU!!
  }   
 // BCSCTL1   = CALBC1_1MHZ;                  // Set DCO
 // DCOCTL    = CALDCO_1MHZ;
  
  P3SEL     = 0x30;                         // P3.4,5 = USCI_A0 TXD/RXD
  UCA0CTL1 |= UCSSEL_2;                     // SMCLK
  UCA0BR0   = 0x84;                         // 3.39 MHz 2400
  UCA0BR1   = 0x05;                         // 3.39 MHz 2400
  UCA0MCTL  = UCBRS2 + UCBRS0;              // Modulation UCBRSx = 5
  //UCA0CTL0   = 0x00;
  UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
  IE2 |= UCA0RXIE;                          // Enable USCI_A0 RX interrupt
 // IE2 |= UCA0TXIE;                        // Enable USCI_A0 TX interrupt

  __bis_SR_register(LPM0_bits + GIE);       // Enter LPM0, interrupts enabled
  while(1)
  {
      
  }
}

// Echo back RXed character, confirm TX buffer is ready first
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
  while (!(IFG2&UCA0TXIFG));                // USCI_A0 TX buffer ready?
  UCA0TXBUF = UCA0RXBUF;                    // TX -> RXed character
 
}

This code is working but not properly.

When I press any key on keyboard...........I get random chars like α, √ etc........

I have used 2400 8-N-1 setting for UART communication.

Kindly let me know whats the problem.
 

Re: UART in MSP430

Hello!

So it means you have an MSP430 with a serial port chip,
for instance MAX3232, and you try to send data with the PC, right?

Just in case: can you check that:
- The bitrate you set (apparently 2400) is also the same on the PC.
- Check the SMClock with a scope to check that it's really the value you
intended to use. There is something unclear: why do you check the
DCO calibration values if you use a 3.39 MHz crystal?
Basically in your code, you don't set any frequency, you just check
the calibration values. So the frequency should be the default DCO.
This means around 1 MHz. So the fastest way to get a start: output
SMCLOCK on one pin (check the data sheet for your device). Then
adapt the UCBRs accordingly.

Another thing: did you check TI's sample codes? I am sure there are
programs pretty close to what you want to do.

Dora.
 

    scorrpeio

    Points: 2
    Helpful Answer Positive Rating
Re: UART in MSP430

HI

Set the DCO to 1.8430 Mhz Or 3.6864MHz Insted of 3.9Mhz

See TI C code for doing so

All the best

Bobi

The microcontroller specialist
 

Re: UART in MSP430

doraemon said:
Hello!

So it means you have an MSP430 with a serial port chip,
for instance MAX3232, and you try to send data with the PC, right?

Just in case: can you check that:
- The bitrate you set (apparently 2400) is also the same on the PC.
- Check the SMClock with a scope to check that it's really the value you
intended to use. There is something unclear: why do you check the
DCO calibration values if you use a 3.39 MHz crystal?
Basically in your code, you don't set any frequency, you just check
the calibration values. So the frequency should be the default DCO.
This means around 1 MHz. So the fastest way to get a start: output
SMCLOCK on one pin (check the data sheet for your device). Then
adapt the UCBRs accordingly.

Another thing: did you check TI's sample codes? I am sure there are
programs pretty close to what you want to do.

Dora.


Thank you..........
Yes the freq is 1MHz as u said........
its working fine now :)
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top