scorrpeio
Full Member level 5
UART in MSP430
Hello,
I am writing a UART code to communicate with PC.
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.
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.