While trying to get my MSP430BT5190 to communicate with another device using the USCI I had issues sending and receiving data so I tried to communicate with the MSP430 itself before connecting to another device. My code worked when connected to a terminal on my computer using a UART interface, but when sending and receiving to itself (ie the USCITX pin is connected to the USCIRX pin) I would only receive the last character in the transmitted sequence a large number of times instead of receiving the entire sequence. It seems to be caused by the interrupt that should handle characters that are received not triggering until the entire sequence has been sent but I'm not sure why the interrupt isn't being triggered. I've put my code below and help would be appreciated in getting it to send/receive the full sequence correctly:
void configure( unsigned, unsigned char, unsigned char );
void uart_send( char * );
int main(void) {
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
/* Configure Pin Muxing P3.5 RXD and P3.4 TXD */
P3SEL |= 0x30;
configure( 104, 1, 0 );
UCA0IE |= UCRXIE + UCTXIE; //enable Rx & Tx interrupt
char command[5] = { 'A', 'T', '\r', 'U', '\0' };
printf( "command is: %s\n", &command);
uart_send(&command);
printf( "command sent successfully\n");
__bis_SR_register(LPM0_bits + GIE); // Enter LPM0, interrupts enabled
}
void configure( unsigned divider, unsigned char fM, unsigned char sM ){
/* Place UCA0 in Reset to be configured */
UCA0CTL1 = UCSWRST;
/* Configure */
UCA0CTL1 = UCSSEL1;
UCA0BR0 = divider & 0xFF;
UCA0BR1 = divider >> 8;
UCA0MCTL = ( (fM & 0xF) << 4 |(sM & 0x7) << 1);
/* Take UCA0 out of reset */
UCA0CTL1 &= ~UCSWRST;
}
void uart_send( char * command ){
while( *command ){
while (!(UCA0IFG & UCTXIFG));
printf( "transmitting %c\n", *command );
UCA0TXBUF = *command;
UCA0IFG &= ~UCTXIFG;
if( !(UCA0IFG & UCTXIFG) ){
printf ("interrupt flag is disabled\n");
}
command++;
}
}
/* Echo back RXed character, confirm TX buffer is ready first */
#pragma vector=USCI_A0_VECTOR
__interrupt void USCI_A0_ISR(void)
{
while (!(UCA0IFG & UCTXIFG));
printf( "char: %c\n", (char)UCA0RXBUF );
UCA0IFG |= UCTXIFG;
}