EmbeddedRelated.com
Forums

MSP430F5419 problems with UARTs

Started by "veronica.cris" October 18, 2010
I'm trying to configure the 2 uarts, I wanna receive serial data in UCA1Rx and I wanna send this data with UCA2Tx. I'm learning about configure UART, I never work with MSP430 before.

I know this code is wrong, if someone could show me what is wrong.

//uart 1
UCA1CTL1 |= UCSWRST; // **Put state machine in reset**
UCA1CTL1 |= UCSSEL_1; // CLK = ACLK
UCA1BR0 = 0x06; // 32k/9600 - 3.41
UCA1BR1 = 0x00; //
UCA1MCTL = 0xFB; // Modulation

//uart2
UCA2CTL1 |= UCSWRST; // **Put state machine in reset**
UCA2CTL1 |= UCSSEL_1; // CLK = ACLK
UCA2BR0 = 0x06; // 32k/9600 - 3.41
UCA2BR1 = 0x00; //
UCA2MCTL = 0x0FB; // Modulation
UCA1CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
UCA2CTL1 &= ~UCSWRST;

UCA1IE |= UCTXIE + UCRXIE; // Enable USCI_A1 TX/RX interrupt

UCA2IE |= UCTXIE + UCRXIE; // Enable USCI_A2 TX/RX interrupt

__bis_SR_register(LPM3_bits + GIE); // Enter LPM3 w/ interrupts enabled
__no_operation(); // For debugger
}
#pragma vector=USCI_A1_VECTOR
__interrupt void USCI_A1_ISR(void)
{
switch(__even_in_range(UCA1IV,4))
{
case 0:break; // Vector 0 - no interrupt
case 2: // Vector 2 - RXIFG
while (!(UCA1IFG&UCTXIFG)); // USCI_A1 TX bufferready?
UCA2TXBUF = UCA1RXBUF; // TX -> RXed character
break;
case 4:
while (!(UCA1IFG&UCTXIFG)); // USCI_A1 TX buffer ready?
UCA2TXBUF = UCA1RXBUF; // TX -> RXed character

break; // Vector 4 - TXIFG
default: break;
}
}
#pragma vector=USCI_A2_VECTOR
__interrupt void USCI_A2_ISR(void)
{
switch(__even_in_range(UCA1IV,4))
{
case 0:break; // Vector 0 - no interrupt
case 2: // Vector 2 - RXIFG
while (!(UCA2IFG&UCTXIFG)); // USCI_A1 TX buffer ready?
UCA2TXBUF = UCA1RXBUF; // TX -> RXed character
break;
case 4:
while (!(UCA2IFG&UCTXIFG)); // USCI_A1 TX buffer ready?
UCA2TXBUF = UCA1RXBUF; // TX -> RXed character

break; // Vector 4 - TXIFG
default: break;
}
}

thanks

Beginning Microcontrollers with the MSP430

IMHO, the USCI_A1 ISR is unnecessary and may actually be causing your problems. Ask yourself why you need a transmit interrupt.

-Steve

-----Original Message-----
From: m... [mailto:m...] On Behalf Of veronica.cris
Sent: Monday, October 18, 2010 12:39 PM
To: m...
Subject: [msp430] MSP430F5419 problems with UARTs

I'm trying to configure the 2 uarts, I wanna receive serial data in UCA1Rx and I wanna send this data with UCA2Tx. I'm learning about configure UART, I never work with MSP430 before.

I know this code is wrong, if someone could show me what is wrong.

//uart 1
UCA1CTL1 |= UCSWRST; // **Put state machine in reset**
UCA1CTL1 |= UCSSEL_1; // CLK = ACLK
UCA1BR0 = 0x06; // 32k/9600 - 3.41
UCA1BR1 = 0x00; //
UCA1MCTL = 0xFB; // Modulation

//uart2
UCA2CTL1 |= UCSWRST; // **Put state machine in reset**
UCA2CTL1 |= UCSSEL_1; // CLK = ACLK
UCA2BR0 = 0x06; // 32k/9600 - 3.41
UCA2BR1 = 0x00; //
UCA2MCTL = 0x0FB; // Modulation
UCA1CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
UCA2CTL1 &= ~UCSWRST;

UCA1IE |= UCTXIE + UCRXIE; // Enable USCI_A1 TX/RX interrupt

UCA2IE |= UCTXIE + UCRXIE; // Enable USCI_A2 TX/RX interrupt

__bis_SR_register(LPM3_bits + GIE); // Enter LPM3 w/ interrupts enabled
__no_operation(); // For debugger
}
#pragma vector=USCI_A1_VECTOR
__interrupt void USCI_A1_ISR(void)
{
switch(__even_in_range(UCA1IV,4))
{
case 0:break; // Vector 0 - no interrupt
case 2: // Vector 2 - RXIFG
while (!(UCA1IFG&UCTXIFG)); // USCI_A1 TX bufferready?
UCA2TXBUF = UCA1RXBUF; // TX -> RXed character
break;
case 4:
while (!(UCA1IFG&UCTXIFG)); // USCI_A1 TX buffer ready?
UCA2TXBUF = UCA1RXBUF; // TX -> RXed character

break; // Vector 4 - TXIFG
default: break;
}
}
#pragma vector=USCI_A2_VECTOR
__interrupt void USCI_A2_ISR(void)
{
switch(__even_in_range(UCA1IV,4))
{
case 0:break; // Vector 0 - no interrupt
case 2: // Vector 2 - RXIFG
while (!(UCA2IFG&UCTXIFG)); // USCI_A1 TX buffer ready?
UCA2TXBUF = UCA1RXBUF; // TX -> RXed character
break;
case 4:
while (!(UCA2IFG&UCTXIFG)); // USCI_A1 TX buffer ready?
UCA2TXBUF = UCA1RXBUF; // TX -> RXed character

break; // Vector 4 - TXIFG
default: break;
}
}

thanks