This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430FR2355: The letter 'A' appears twice???

Part Number: MSP430FR2355


Can someone tell me how to get around the following:  I produce a command, a radio echoes the command back I then produce "ACK" however my code is producing "AACK"....I am not sure how to get around this or for that matter why A is occurring twice...If I try and load the UCA1TXBUF outside the ISR it does not help???

The code:

#include <msp430.h>
#include <string.h>
#include <stdint.h>
#include "rc.h"
#include "LPRSradio.h"

volatile char *pRx;
char incoming[20];
const char *pTx;
const char *configCmdAck[] = {"ER_CMD#a01", "ER_CMD#W2", "ER_CMD#b1"};
const char *testack = "ACK";
uint8_t i = 0;
boolean tx = T;
int k;
boolean redflag = F;

int main(void)

{
    WDTCTL = WDTPW | WDTHOLD;   // stop watchdog timer

    IOconfig;
    initClockTo16MHz();
    initUART();
    pRx = incoming;
    pTx = configCmdAck[0];
    while (1)
    {
        __bis_SR_register(LPM3_bits + GIE); //go to sleep: LPM3
        if (tx) {
            pTx++;
        }
        else {
            if (!strncmp(incoming, configCmdAck[i], 10))
            {
                pTx = testack;
                i++;
                UCA1IFG |= UCTXIFG;
            }
            pRx++;
        }
    }
}


#pragma vector=USCI_A1_VECTOR
__interrupt void M(void)
{
    switch(__even_in_range(UCA1IV, USCI_UART_UCTXCPTIFG))
    {
      case USCI_NONE: break;
      case USCI_UART_UCRXIFG:
          tx = F;
          *pRx = UCA1RXBUF;
          __bic_SR_register_on_exit(LPM3_bits);
          break;
      case USCI_UART_UCTXIFG:
          tx = T;
          if (*pTx != '\0')
              UCA1TXBUF = *pTx;
          __bic_SR_register_on_exit(LPM3_bits);
          break;
      case USCI_UART_UCSTTIFG: break;
      case USCI_UART_UCTXCPTIFG: break;
    }
}

The pic:

badACK.docx

  • If the UART is idle, and you enable TXIE, you can expect to immediately get two TXIFGs in quick succession. The first byte goes right through to the shift register, and the second stops in the Tx holding register while the first is being shifted out. main() won't execute between these two interrupts.

    You should probably do the pTx++ in the ISR, right after you load TXBUF.

  • Yes I realized my issue, thank  you.....I moved the IFG flag to the last line to be processed bcz it looked like I was pointing to the 'A', interrupting, pushing it out, waking up, processing pRx++ , then because the buffer was empty another interrupt occured, pushed 'A' out again, etc....hench "AACK"..... 

                if (!strncmp(incoming, configCmdAck[i], 10))
                {
                    pTx = testack;
                    i++;
                    redflag = T;
                }
                pRx++;
                if (redflag) {
                    redflag = F;
    /*URGENT: Setting UCTXIFG must be the last line of code. If set earlier we will go into ISR, come out and process the next line of code
     * before going back into ISR because TXIFG will get set because of TXBUF going empty...This unfortunate event will promote a double character instance.
     * redflag will alert us that we want to go back into ISR...hence prepare everything, create redflag then use it at very end of if statement to generate ISR
     * such that when we return we will move to next line of code (ie LPM3 sleep), then TXIFG will wake us at beginning again.
    */
                    UCA1IFG |= UCTXIFG;
                }
    

**Attention** This is a public forum