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.
for a project we wanted to transmit data serially from our adc to the pc using UART. since real time data was not being transmitted properly we tried to transmit a constant value "1023" through the UART of msp430g2553. we transmitted the value by splitting it as MSB and LSB and checked the recieved value in "TERMINAL by br@yy+" "TERA TERM" and "PUTTY". However we found that the data was lost while being transmitted.
example:-
the expected output is
10 23 10 23 10 23 10 23 10 23.................
but we are getting output as
10 23 10 10 10 23 10 23 23 10 10 23 10......
also every time we run the code the output changes i.e. there is no exact pattern in which error occurs.
we tried various other ways like changing baud rated, adding delay, etc.. but none of them worked.
please help us out to know our error and provide the solution for the same.
we provide you with the code that we have used.
------THE CODE-----
#include<msp430g2553.h>
unsigned int value=1023;
void main(void)
{
WDCTL = WDTPW | WDTHOLD;
BCSCTL1=CALBC_1MHZ;
DCOCTL=CALDCO_1MHZ;
P1SEL = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
P1SEL2 = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
UCA0CTL1 |= UCSSEL_2; // SMCLK
UCA0BR0 = 104; // Set Baud rate (1MHz CPU clock)/(9600 baud) (lower byte)
UCA0BR1 = 0; // Set Baud rate to (1MHz CPU clock)/(9600 baud) (upper byte)
UCA0MCTL = UCBRS0; // Modulation UCBRSx = 1
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
while(1)
{
while (!(IFG2 & UCA0TXIFG)); // Wait until TX buffer ready?
UCA0TXBUF = value >> 8; // Send MSB first
while (!(IFG2 & UCA0TXIFG)); // Wait until TX buffer ready?
UCA0TXBUF = (value & 0x00FF); // Send LSB
}
}
I’ve seen this happening on systems where the receiver wasn’t fast enough to read the one byte before the next was coming in. Usually an MSP with an RX ISR, where an different ISR was taking too long.
However, I wouldn’t expect this on a fairly recent PC, especially not with an UART with FIFO.
The code looks good. And since all bytes are received properly (if at all), I don’t think there is an electrical problem.
However, it might be that the (probably used) USB/serial adaptor (actually an MCU with UART and USB) has timing problems when receiving data. Maybe when preparing or receiving an USB package. Yet with 9600Bd, this is quite unlikely.
exactly even we are not able to trace the roots of the problem.
so we tried the same using "ENERGIA" sketch. the serial communication took place succesfully without any loss of data. however we want to send data that is sensed using the ADC. in energia we are not able to find anything to configure the adc . we need the sampling frequency as 100KHZ which we are not able to do in energia.
so the situation is using code composer we are getting proper ADC output but no serial transmission and using energia we are getting faithful serial transmission but no proper adc output.
please suggest a solution (with code composer or energia) so that adc works on 100KHZ and the data is transmitted faithfully through UART.
I really don’t know what’s going on. The waiting loops are where they should, so you shouldn’t overwrite TXBUF before it has been fetched for output.
You also observe “23 23” patterns, which means your code is not resetting for some reason (which could explain “10 10” patterns)
The only thing I noticed that in the pasted code you set “value = 1023”, not 0x1023. So the bytes you send are actually 0x03 and 0xff. Or you made a mistake when posting your code. :)
**Attention** This is a public forum