简体   繁体   中英

Data inconsistency in XBee send and receive. Embedded C

I want send a string in the following format from a serial port in embedded C. I am using a Silicon Labs microcontroller. The desired output is

"01001ODR0001\r\n"
"01002ODR0001\r\n"
"01003ODR0001\r\n"

However, when I send the message, there is some randome behavor and the output comes in the following format.

    0R00110
 010
120 0D
   01001ODR0001
0R0ODR0000
1OD01O01R10R
            01002OR0001
0O012000

I use the following method for it

sendToXbee("01001ODR0001\r\n");

void sendToXbee(unsigned char *msg) {
    while (*msg != '\0')     //Checking up to null char
    {
        SerTx(*msg);
        msg++;
        Delay(1);
    }
}

void SerTx(unsigned char x) {
    SBUF0 = x;
    while (TI0 == 0)
        ;
    TI0 = 0;
}

/**
 * Delay
 */
void Delay(unsigned char temp) {
    unsigned int i, j;

    for (i = 0; i <= temp; i++) {
        for (j = 0; j <= 5000; j++)
            ;
    }
}

Is there a better way of doing this?

Hi Guys thanks for the help. It seems that I was using a screen command on the terminal and at the same time running a python script that was using the same the object and hence the data inconsistency. if u see below the terminal output is better but still not perfect

04001ODR0001
04001OD000
04002ODR001
04002ODR0000
04003ODR0001
04003ODR0000
04004DR0001
04004ODR0000
04005ODR0001
04005ODR000
04004OD0001
0404ODR0000
04003ODR001
04003ODR0000
04003OR0001
04003ODR000
04003ODR001
0403OR000100
04003ODR0000
            0400ODR0001
4003ODR000
04003OR0001
0400ODR0000

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM