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

nrf52832 uart tx problem

Hi,

I use UARTE peripheral when i communicate wih PC. 

This code works. Send 4 bytes. 

bno_tx_buf[0]=0xAA;
bno_tx_buf[1]=0x01;
bno_tx_buf[2]=0x00;
bno_tx_buf[3]=0x01;

NRF_UARTE0->TXD.MAXCNT = 4 ; 
NRF_UARTE0->TXD.PTR = (uint32_t)&bno_tx_buf[0];
NRF_UARTE0->TASKS_STARTTX = 1;
while (NRF_UARTE0->EVENTS_ENDTX == 0)
{
}
NRF_UARTE0->TASKS_STOPTX = 1;
while (NRF_UARTE0->EVENTS_TXSTOPPED == 0);

But, if i add a delay, send 2 bytes then 2 bytes. Only first 2 bytes sent. After that uart don't send any character. 

NRF_UARTE0->TXD.MAXCNT = 2 ; 
NRF_UARTE0->TXD.PTR = (uint32_t)&bno_tx_buf[0];
NRF_UARTE0->TASKS_STARTTX = 1;
while (NRF_UARTE0->EVENTS_ENDTX == 0)
{
}
NRF_UARTE0->TASKS_STOPTX = 1;
while (NRF_UARTE0->EVENTS_TXSTOPPED == 0);

//delay

NRF_UARTE0->TXD.MAXCNT = 2 ; 

NRF_UARTE0->TASKS_STARTTX = 1;
while (NRF_UARTE0->EVENTS_ENDTX == 0)
{
}
NRF_UARTE0->TASKS_STOPTX = 1;
while (NRF_UARTE0->EVENTS_TXSTOPPED == 0);

Is there any configuration or initalization problem, that i do? I want to send buffer data continuously in loop, but uart doesn't work again except first tx.

Thanks

Berker

Parents
  • Hi,

    You need to clear the ENDTX event after your first transfer. Otherwise ENDTX = 1 once you start your next transfer and the code doesn't stop in the second while (NRF_UARTE0->EVENTS_ENDTX == 0) loop, but powers through instead, and stops the UART before the second transfer has started.

    ...
    NRF_UARTE0->TXD.MAXCNT = 2 ; 
    NRF_UARTE0->TXD.PTR = (uint32_t)&bno_tx_buf[0];
    NRF_UARTE0->TASKS_STARTTX = 1;
    while (NRF_UARTE0->EVENTS_ENDTX == 0)
    {
    }
    NRF_UARTE0->EVENTS_ENDTX = 0; // <- CLEAR ENDTX EVENT AFTER USE
    
    NRF_UARTE0->TASKS_STOPTX = 1;
    while (NRF_UARTE0->EVENTS_TXSTOPPED == 0);
    
    //delay
    
    NRF_UARTE0->TXD.MAXCNT = 2 ; 
    
    NRF_UARTE0->TASKS_STARTTX = 1;
    ...

Reply
  • Hi,

    You need to clear the ENDTX event after your first transfer. Otherwise ENDTX = 1 once you start your next transfer and the code doesn't stop in the second while (NRF_UARTE0->EVENTS_ENDTX == 0) loop, but powers through instead, and stops the UART before the second transfer has started.

    ...
    NRF_UARTE0->TXD.MAXCNT = 2 ; 
    NRF_UARTE0->TXD.PTR = (uint32_t)&bno_tx_buf[0];
    NRF_UARTE0->TASKS_STARTTX = 1;
    while (NRF_UARTE0->EVENTS_ENDTX == 0)
    {
    }
    NRF_UARTE0->EVENTS_ENDTX = 0; // <- CLEAR ENDTX EVENT AFTER USE
    
    NRF_UARTE0->TASKS_STOPTX = 1;
    while (NRF_UARTE0->EVENTS_TXSTOPPED == 0);
    
    //delay
    
    NRF_UARTE0->TXD.MAXCNT = 2 ; 
    
    NRF_UARTE0->TASKS_STARTTX = 1;
    ...

Children
No Data
Related