Tool/software: Code Composer Studio
Hi,
I am using the below code for UART. I am trying to send 4 bytes of data from terminal on my PC to P4.5 of MSP430F5342 . It is sent being back to terminal from P4.4 of MSP430. The below code is being used to loop back. I am receiving only 2 bytes back on the terminal(1st and last bytes only).
#include <msp430.h>
unsigned char bytescount=0;
unsigned char received_value=0;
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P4SEL |= BIT4+BIT5; // P4.4,5
UCA1CTL1 |= UCSWRST; // **Put state machine in reset**
UCA1CTL1 |= UCSSEL_2; // SMCLK
UCA1BR0 = 9; // 1MHz 115200 (see User's Guide)
UCA1BR1 = 0; // 1MHz 115200
UCA1MCTL |= UCBRS_1 + UCBRF_0; // Modulation UCBRSx=1, UCBRFx=0
UCA1CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
UCA1IE |= UCRXIE; // Enable USCI_A0 RX interrupt
__bis_SR_register( GIE); // Enter LPM0, interrupts enabled
// __no_operation(); // For debugger
// P3.3,4 = USCI_A0 TXD/RXD
while(1);
}
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=USCI_A1_VECTOR
__interrupt void USCI_A1_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(USCI_A1_VECTOR))) USCI_A1_ISR (void)
#else
#error Compiler not supported!
#endif
{
volatile unsigned int i;
switch(__even_in_range(UCA1IV,4))
{
case 0: break; // Vector 0 - no interrupt
case 2: // Vector 2 - RXIFG
while (!(UCA1IFG&UCTXIFG)); // USCI_A0 RX buffer ready?
// Send next value
received_value=UCA1RXBUF;
bytescount++;
UCA1TXBUF=received_value;
break;
case 4: break; // Vector 4 - TXIFG
default: break;
}
}
Eg: When I send 0x01 0x02 0x03 0x04 I am receiving only 0x01 and 0x04 back on the terminal
If I send only 0x01 and 0x02 I receive them both correctly.
The count "bytescount" present in ISR increments only twice every time I send the data IRRESPECTIVE of the length of the data. i tried sent 2 3 4 5 bytes. Whatever may be the number of bytes sent from terminal I am receiving only 1st and last bytes back and ISR is entered only twice every time. Receive ISR is supposed to be entered for every byte received but it is not happening so. Kindly suggest corrections.