Other Parts Discussed in Thread: MSP-FET
Hello All,
Thank you for taking the time to look at this post. I am currently attempting to write a simple Tx and Rx program that will allow me to talk to a specific module. The module, at the moment, is independent of the question as I would like to understand what I am doing wrong in the code below. First of all, I have a MSP430FR5994 microcontroller that has Tx (P2.1) and Rx (P2.0) shorted together to form a loopback. As you can (hopefully) see in the program, I am attempting to write the message: "AT+GSN" to the Tx Buffer. Subsequently, as the Tx and Rx pins are shorted together, I would like to reconstruct the full message (one byte at a time of course) from the Rx Buffer. I am obviously doing something wrong as I am currently only receiving the last two values 'S' and 'N" at the moment. I have also attached an image showing the microcontroller in low power mode after the message has been sent. Note that I paused the program to retrieve the image. I am sure the system was done sending the data at the time as it entered the LPM0 statement.
Could someone please point me in the right direction regarding this issue?
P.S. Sorry about the messy code. This isn't going to be used for any form of production, just to test a certain device on my PCB. I previously used this code with a loopback to my PC through the MSP-FET and it worked excellently.
Thank you.
CODE:
#include <msp430fr5994.h>
/*****************************************************************************************************************************
* main.c Uses P2
*
*****************************************************************************************************************************/
char reconstruct[100] = "";
int position = 0;
int main(void) {
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
// Configure GPIO
P2SEL0 &= ~(BIT0 | BIT1);
P2SEL1 |= BIT0 | BIT1; // USCI_A0 UART operation
// Disable the GPIO power-on default high-impedance mode to activate
// previously configured port settings
PM5CTL0 &= ~LOCKLPM5;
// Configure USCI_A0 for UART mode
UCA0CTLW0 = UCSWRST;
UCA0CTLW0 |= UCSSEL__SMCLK; // CLK = SMCLK
// Baud Rate calculation
// 8000000/(16*9600) = 52.083
// Fractional portion = 0.083
// UCBRFx = int ( (52.083-52)*16) = 1
UCA0BR0 = 16; // 8000000/16/9600
//UCA0MCTLW |= UCOS16 | UCBRF_1 | 0x4900;
UCA0CTLW0 &= ~UCSWRST; // Initialize eUSCI
UCA0IE |= UCRXIE; // Enable USCI_A0 RX interrupt
//UCA0TXBUF = 0x00; //test send 'A'
char message[] = "AT+GSN";
int i = 0;
int k = 0;
for(i = 0; i<sizeof(message); i++)
{
while(!(UCA0IFG & UCTXIFG));
UCA0TXBUF=message[i];
//UCA0IFG &= ~UCTXIFG; // Clear interrupt
//for(k=0;k<50;k++){}
}
__bis_SR_register(LPM0_bits | GIE); // Enter LPM3, interrupts enabled
__no_operation(); // For debugger
}
#pragma vector=USCI_A0_VECTOR
__interrupt void USCI_A0_ISR(void)
{
switch(__even_in_range(UCA0IV, USCI_UART_UCTXCPTIFG))
{
case USCI_NONE: break;
case USCI_UART_UCRXIFG:
while(!(UCA3IFG&UCTXIFG));
reconstruct[position]=UCA0RXBUF; //echo
position++;
__no_operation();
break;
case USCI_UART_UCTXIFG: break;
case USCI_UART_UCSTTIFG: break;
case USCI_UART_UCTXCPTIFG: break;
}
}