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.

MSP430FR6922: MSP430FR6922: byte missing in UART interrupt

Part Number: MSP430FR6922

Hi all,
I have question regarding msp430 controller. I am working on msp430fr6922 controller. I am trying to communicate between MSP430 controller and Raspi using serial USB to TTL cable. I have attached code for your refernce. UART is working on ACLK which is 32.768 kHZ and baud rate set is 9600. In receive mode, sometimes data bytes are missing. What is the reason??


#include "common.h"

int RPI_UART(void)
{
// Configure USCI_A0 for UART mode
UCA0CTLW0 = UCSWRST; // Put eUSCI in reset
UCA0CTLW0 |= UCSSEL__ACLK; // CLK = SMCLK
// Baud Rate calculation
// 8000000/(16*9600) = 52.083
// Fractional portion = 0.083
// User's Guide Table 21-4: UCBRSx = 0x04
// UCBRFx = int ( (52.083-52)*16) = 1
UCA0BR0 = 3; // 9600 baud
UCA0MCTLW |= 0x5300; // 32768/9600 - INT(32768/9600)=0.41
// UCBRSx value = 0x53 (See UG)
UCA0BR1 = 0;
UCA0CTLW0 &= ~UCSWRST; // Initialize eUSCI
UCA0IE |= UCRXIE; // Enable USCI_A0 RX interrupt

}

#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=USCI_A0_VECTOR
__interrupt void USCI_A0_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(USCI_A0_VECTOR))) USCI_A0_ISR (void)
#else
#error Compiler not supported!
#endif
{
switch(__even_in_range(UCA0IV, USCI_UART_UCTXCPTIFG))
{

case USCI_NONE: break;
case USCI_UART_UCRXIFG:

while(!(UCA0IFG&UCTXIFG));
RXDATA[p++]=UCA0RXBUF;

if (RXDATA[0]==0x01)
{
if(p==3)
{
p=0;
giNewFrameFlag=1;
}
}
else
{
p=0;
}
break;

case USCI_UART_UCTXIFG: break;
case USCI_UART_UCSTTIFG: break;
case USCI_UART_UCTXCPTIFG: break;
}
}

  • Hi Sayali,

    you say you sometimes miss data bytes, so the basic function is right.

    I have check your UART configuration, and the follow parameter is more suitable:

    UCA0MCTLW |= 0x5300 -> UCA0MCTLW |= 0x9200

    It can be checked in Table 30-5 in User's Guide.

    Set BCURSx =0x53 will cause larger RX Error, and make you lose data. 

    Best Regards

    Sal

  • Why are you checking TXIFG in your receive interrupt?

    I see something resembling buffering of the receive data in the ISR. So how exactly does your failure occur? Packets don't start? Missing characters in a packet? Hopefully there is an error recovery mechanism somewhere for when an ill formed packet arrives.

  • Hi Sal,

        As per your suggestion I changed UCA0MCTLW value to 0x9200 but, still sometimes I lost first 3 bytes.

    Every time Raspi send 4 bytes to msp430 controller which is "0x01,0x0F,0x04,0xFF". But, sometime controller receive only last byte i.e. 0xFF in 1st position of array. 1st 3 bytes are missing. 

    please suggest is this issue regarding MSP430FR6922 controller or something wrong in the code??

  • Hi Sayali,

    If the issue still exists, I think you should recheck your code. 

    As David said, you set '!(UCA0IFG&UCTXIFG)' as condition of a 'while' function, which means that when UCTXIFG =0, the loop breaks. It is used when you need transmit data and should check TX Buffer whether is empty. This will cause a situation that, when you get a new data from UCA0RXBUF, but due to 'UCTXIFG=1', so you will not update data until 'UCTXIFG=0', and then you lose data.

    As for your code of update 'RXDATA', when you miss the first byte, then the following three byte will be put in RXDATA[0], so there will only one byte exist, which is the last byte - '0xFF'.

    If not necessary, please remove 'while(!(UCA0IFG&UCTXIFG))' and try again. Or you may take the above into consideration, and optimize your code functionality.

    Best Regards

    Sal

**Attention** This is a public forum