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.

UART data corrupted

Hi,

I am trying to use the USART for UART communication on the CC1110f32. I am using the following code and I am receiving data on the other end as expected (every three seconds) but every time I receive the wrong character. Instead of receiving the character a (0x61) every three seconds I am instead receiving the character á (0xe1) every three seconds. I have tried different characters with the same problem and also the code sample UART_CC111x_CC251x_ISR.c which again had the same problem when connected to my computer.

I am fairly confident that everything is set up correctly and that I am using the correct baud rate on my terminal.

#include "hal.h"
#include "hal_types.h"
#include "hal_defs.h"
#include "cc8051/hal_cc8051.h"
#include "ioCCxx10_bitdef.h"
#include <ioCC1110.h>

void sleepMS(int ms) {
 int j;
 while (--ms > 0) { 
  for (j=0; j<400;j++) asm (" NOP"); // about 1 millisecond
 };
}

int main(void)
{
    /* Set function of P0_0 to general purpose I/O */
    P0SEL &= BIT0;
    /* Write value to pin. Note that this is a direct bit access.
     * Also note that the value is set before the pin is configured
     * as an output, as in some cases the value of the output needs
     * to be defined before the output is driven (e.g. to avoid
     * conflicts if the signal is shared with an other device)
     */
    P0_0 = 1;
    
    char ch = 'a';

    /* Change direction to output */
    P0DIR |= BIT0;
    UART_SETUP(0,9600,HIGH_STOP);
    while(1)
    {
        sleepMS(3000);
        UART_SEND(0, ch);
        P0_0 ^= 1;
    }

    return 0;
}

Thank you for your help,

Robert Nash.

  • Ok, I have made some progress of a sort.

    When sending the string "Hello, world ." one character at a time using the method above I receive the string "Èåììï, ÷ïòìä." If I then compare the binary for these two strings I come to an interesting conclusion.

    Intended

    01001000 01100101 01101100 01101100 01101111 00101100 01110111 01101111 01110010 01101100 01100100 00101110

    Actual

    11001000 11100101 11101100 11101100 11101111 00101100 11110111 11101111 11110010 11101100 11100100 00101110

    As can be seen the first bit of each byte is being sent high instead of low unless the second bit is also low. The result of this is that on the receiving end I am able to construct a valid string by adding 128 to each byte received. This is obviously a little strange and I wonder if I am possibly making  some sought of configuration error.

    Thank you again for your help.