Other Parts Discussed in Thread: MSP430F5529, MSP430G2553
Hi all,
I am trying to transmit data to a PC through UART under BR 460800 using MSP430f5529 lauchpad. In the PC side, matlab serial module is used for data collecting. The data transmitted (int type) goes up from 0 to 65535 and goes back down to 0. The process iterates until 2621400 data is sent out. While in the matlab side, for example, the data received is 2582206. 39194 of data are missed. There are three places where the received data does not increase smoothly. For example, the received bytes are (195 25 195 26 195 27 222 229 221 229). I am struggling with this problem. My application is to send out data from ADC to a PC through UART consistently. The transmission time would be as long as 1 hour. I have to figure out the missing data problem or the data collected can not be trusted.
The code is shown below.
#include <msp430.h>
unsigned int ADCdata;
unsigned int count=0;
unsigned char up=1;
int main(void)
{
WDTCTL = WDTPW+WDTHOLD; // Stop WDT
ADCdata=0;
P3SEL |= BIT3+BIT4;
UCSCTL3 = SELREF_2; // Set DCO FLL reference = REFO
UCSCTL4 |= SELA_2; // Set ACLK = REFO
UCSCTL0 = 0x0000; // Set lowest possible DCOx, MODx
// Loop until XT1,XT2 & DCO stabilizes - In this case only DCO has to stabilize
do
{
UCSCTL7 &= ~(XT2OFFG + XT1LFOFFG + DCOFFG);
// Clear XT2,XT1,DCO fault flags
SFRIFG1 &= ~OFIFG; // Clear fault flags
}while (SFRIFG1&OFIFG); // Test oscillator fault flag
__bis_SR_register(SCG0); // Disable the FLL control loop
UCSCTL1 = DCORSEL_5; // Select DCO range 20MHz operation
UCSCTL2 |= 609; // Set DCO Multiplier for 20MHz
__bic_SR_register(SCG0); // Enable the FLL control loop
__delay_cycles(250000);
/*UCA0 UART Initialization*/
UCA0CTL1 |= UCSSEL_2+UCSWRST; // CLK = SCLK
UCA0BR0 = 43; // 20MHz 480600
UCA0BR1 = 0; // 20MHz 480600
UCA0MCTL =UCBRS_3; // Modulation UCBRSx = 3
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
while(1)
{
UCA0TXBUF= ADCdata>>8;
while (!(UCA0IFG&UCTXIFG)); // USCI_A0 TX buffer ready?
UCA0TXBUF = ADCdata; // TX -> RXed character
while (!(UCA0IFG&UCTXIFG));
if(up==1)
ADCdata=ADCdata+1;
else
ADCdata=ADCdata-1;
if (ADCdata==0xFFFF)
{
up=0;
}
else if (ADCdata==0x0000)
{
up=1;
count=count+1;
}
if (count==20)
{
UCA0CTL1 |= UCSWRST;
}
}
}