This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Strange UART behaviour

Hello fellow devlopers.

I am experienceing very odd behaviour from the UART peripheral. I am trying to ouput a uint8_t[48] array from the UART termainl. I am using this simple code

while (i <48) 
{
uint8_t UART_Val;
UART_Val = Meta_data[i];
NRF_UART0->TXD = UART_Val;
while (NRF_UART0->EVENTS_TXDRDY != 1)
{
    // Wait for TXD data to be sent.
}
NRF_UART0->EVENTS_TXDRDY = 0;
i = i+1;
}

ofcourse I have prviously defined i as a 0 integer. The thing is, I only get the first 2 or three elements of the array to show up when I run the code. More stragnly, If I debugg the device to see what is wrong, all elements end up showing up. I think this is a case of synchonisation. Does anybody have a comment to add to this. Thanks in Advance.

  • Hi. What program are you using to receive the uart string? If the program expects a text string it will for example terminate on 0x00 characters or '\n' (newline) characters. See if you can print the data as raw values on the receiver end. You can also try to vary the contents of the Meta_data array, to see if this has any effect. Does the while loop finish or does it crash after 2-3 iterations?

  • You need to trigger a task.

    I would try

    while (i < 48) {

    uint8_t UART_Val; UART_Val = Meta_data[i];

    NRF_UART0->EVENTS_TXDRDY = 0;

    NRF_UART0->NRF_UART_TASK_STARTTX = 1;

    NRF_UART0->TXD = UART_Val;

    while (NRF_UART0->EVENTS_TXDRDY != 1) {

    // Wait for TXD data to be sent.
    

    }

    i++; }

    but check out the example uart code in the SDK. and why arent you using that - it simplifies things?

    let me know if it works!

    -Mike

  • Thank you Michael for your quick reply...I actually am using the exmaple code. I was using the c library stright but ended up coping the fuction into my main code and adjusting it from here as the debugging was easier.. with regard to your code..I am not able to compie as I get an error struct "" has no field "NRF_UART_TASK_STARTTX" :(

  • mhm..I am just trying to read uint8_t data. There is simple funciton provided in the UART library found in the SDK that can do this which am using. The thing, I am unable to tell if the loop executes completely or not because when I try to debug the program, everything runs perfectly. Am thinking this is because when your are debugging you are giving good time for the handshake synchonisation between the PC and the nordic chip. I have tried to add delay but could not get it to work. Strange indeed

  • NRF_UART0->TASKS_STARTTX = 1;

1 2