Hello,
I'm working with the msp430 uart to interface with another component. My Tx function works just fine, but when I try to recieve a string of characters, I only end up getting the last one. I think this is because the Rx flag is only triggering once (though I thought it would trigger each time the rx buffer filled), but it could be some other issue. Please help. My code is below.
/*
* main.c
*/
#include "msp430.h"
#include "stdio.h"
// Transfers the given string over the UCSI UART port. Uses explicit length, instead
// of looking for a null byte to terminate the string.
void TXString(char* string, int length, char* check){
int pointer;
for( pointer = 0; pointer < length; pointer++)
{
UCA1TXBUF = string[pointer];
check[pointer]=UCA1TXBUF;
while (!(UCA1IFG & UCTXIFG)); // USCI_A0 TX buffer ready?
}
}
volatile int i=0;
void main(void) {
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
char output[2];
output[0]='r';
output[1]='\r';
P5DIR |= (0x0040);
P5DIR &= ~(0x0080);
P5SEL |= (0x0040);
P5SEL |= (0x0080);
// P5.6,7 = USCI_A1 TXD/RXD
UCA1CTL1 |= UCSWRST; // **Put state machine in reset**
UCA1CTL1 |= UCSSEL_2; //Select 1MHz clock
UCA1BR0 = 27; // baud rate=38400 (User's guide)
UCA1MCTL |= UCBRS_2+UCBRF_0; // Modulation UCBRSx=2, UCBRFx=0
UCA1CTL0 = 0; //Does all of the below things
// Parity disabled
// 8-bit data length
// 1 Stop bit
//Asynchronous mode
UCA1CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
UCA1IE |= UCRXIE+UCTXIE; // Enable USCI_A1 RX interrupt, AND Enable USCI_A1 TX interrupt
char check[20];
__enable_interrupt(); //Enabling interrupts without entering low power mode
P1DIR |= 0x01; // Set P1.0 to output direction for test
for(;;){
volatile unsigned int i; // volatile to prevent optimization
P1OUT ^= 0x01; // Toggle P1.0 using exclusive-OR
TXString(output, 2, check);
i = 100000000; // SW Delay
do i--;
while (i != 0);
}
}
#pragma vector=USCI_A1_VECTOR
__interrupt void USCI_A1_ISR(void)
{
char check2[20];
switch(__even_in_range(UCA1IV,4))
{
case 0:break; // Vector 0 - no interrupt
case 2: // Vector 2 - RXIFG
puts("Received!");
check2[i]=UCA1RXBUF; //This might not do what I think it does
i++;
printf("Check2[0]: %c \n", check2[0]);
printf("Check2[1]: %c \n", check2[1]);
printf("Check2[2]: %c \n", check2[2]);
printf("Check2[3]: %c \n", check2[3]);
printf("Check2[4]: %c \n", check2[4]);
printf("Check2[5]: %c \n", check2[5]);
printf("Check2[6]: %c \n", check2[6]);
printf("Check2[7]: %c \n", check2[7]);
break;
case 4:
puts("Transmitted!");
break; // Vector 4 - TXIFG
default: break;
}
}