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

How to configure the UARTE0 correct?

Hi all

I'm struggling with the easyDMA UART of nrf52. I've got a preview nrf52-DK here where I wanted to make a simple example with the following code but I never reach the ENDRX event even if I send 20 or more bytes to the DK (pin 8). Also in debug mode I can't see that any byte reaches the rxbuffer.

Do you guys see why is that? What did I make wrong in the initiation?

Thank you all in advance for your support!

#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include "nrf_delay.h"
#include "nrf_gpio.h"
#include "boards.h"
#include "nrf_uarte.h"

const uint8_t leds_list[LEDS_NUMBER] = LEDS_LIST;

void UARTE0_UART0_IRQHandler(){

	if(NRF_UARTE0->EVENTS_ENDRX){
		LEDS_INVERT(1 << leds_list[3]);
	}

}


int main(void)
{

	uint8_t txBuffer[20] = {0};
	uint8_t rxBuffer[20] = {0};

    NRF_UARTE0->BAUDRATE = NRF_UARTE_BAUDRATE_9600;
    NRF_UARTE0->PSEL.TXD = TX_PIN_NUMBER;
    NRF_UARTE0->PSEL.RXD = RX_PIN_NUMBER;
    NRF_UARTE0->CONFIG = NRF_UARTE_HWFC_DISABLED;
    NRF_UARTE0->ENABLE = (UARTE_ENABLE_ENABLE_Enabled << UARTE_ENABLE_ENABLE_Pos);

    NRF_UARTE0->TXD.PTR = (uint32_t)((uint8_t *) txBuffer);
    NRF_UARTE0->TXD.MAXCNT = sizeof(txBuffer);
    NRF_UARTE0->TASKS_STARTTX = 0;

    NRF_UARTE0->RXD.PTR = (uint32_t)((uint8_t *) rxBuffer);
    NRF_UARTE0->RXD.MAXCNT = sizeof(rxBuffer);
    NRF_UARTE0->TASKS_STARTRX = 1;


    NRF_UARTE0->INTENCLR = 0xFFFFFFFF;
    NRF_UARTE0->INTENSET = NRF_UARTE_INT_ENDRX_MASK;

    NVIC_ClearPendingIRQ(UARTE0_UART0_IRQn);
    NVIC_SetPriority(UARTE0_UART0_IRQn, 1);
    NVIC_EnableIRQ(UARTE0_UART0_IRQn);



    // Configure LED-pins as outputs.
    LEDS_CONFIGURE(LEDS_MASK);
    if(NRF_UARTE0->EVENTS_RXSTARTED){
    	LEDS_INVERT(1 << leds_list[1]);
    }


    while (true)
    {


    }
}
Parents
  • Hi, ran the exact same code on the preview kit and did receive the EVENTS_ENDRX with the correct data. Have you checked if tx works?

    Description of my setup:

    • on board Segger chip used as usb<->uart bridge
    • Terra term (serial terminal) on windows 7

    Just a note, generally you should have static allocation of your buffers, Although it shouldn't be a problem in this example.

    Attachment:

  • Thank you both for you're response and you're hint with the static allocation of the buffers!

    Unfortunately the whole system still doesn't work for me. I have the DK connected to my PC and I see the COM Port in my device manger. I'm also able to connect the COM port to a terminal app (tera term and hterm) but I can't send or receive any data (I also tested with different PC's) :-(.

    Did the LED[3] switch off in your testsystem? Are you also using Pin 6 (TX) and 8 (RX)? Is there maybe a special driver I have to install? Or did you have to make any special configuration for the Segger chip? As IDE I'm using eclipse with gcc.

    Here's the updated code with TX and static buffers:

    #include <stdbool.h>
    #include <stdint.h>
    #include <string.h>
    #include "nrf_delay.h"
    #include "nrf_gpio.h"
    #include "boards.h"
    #include "nrf_uarte.h"
    
    const uint8_t leds_list[LEDS_NUMBER] = LEDS_LIST;
    
    void UARTE0_UART0_IRQHandler(){
    
        if(NRF_UARTE0->EVENTS_ENDRX){
            LEDS_INVERT(1 << leds_list[3]);
        }
    
    }
    
    
    int main(void)
    {
    
    	static uint8_t txBuffer[5] = {'h','e','l','l','o',};
    	static uint8_t rxBuffer[20] = {0};
    
        NRF_UARTE0->BAUDRATE = NRF_UARTE_BAUDRATE_9600;
        NRF_UARTE0->PSEL.TXD = TX_PIN_NUMBER;
        NRF_UARTE0->PSEL.RXD = RX_PIN_NUMBER;
        NRF_UARTE0->CONFIG = NRF_UARTE_HWFC_DISABLED;
        NRF_UARTE0->ENABLE = (UARTE_ENABLE_ENABLE_Enabled << UARTE_ENABLE_ENABLE_Pos);
    
        NRF_UARTE0->TXD.PTR = (uint32_t)((uint8_t *) txBuffer);
        NRF_UARTE0->TXD.MAXCNT = sizeof(txBuffer);
        NRF_UARTE0->TASKS_STARTTX = 0;
    
        NRF_UARTE0->RXD.PTR = (uint32_t)((uint8_t *) rxBuffer);
        NRF_UARTE0->RXD.MAXCNT = sizeof(rxBuffer);
        NRF_UARTE0->TASKS_STARTRX = 1;
    
    
        NRF_UARTE0->INTENCLR = 0xFFFFFFFF;
        NRF_UARTE0->INTENSET = NRF_UARTE_INT_ENDRX_MASK;
    
        NVIC_ClearPendingIRQ(UARTE0_UART0_IRQn);
        NVIC_SetPriority(UARTE0_UART0_IRQn, 1);
        NVIC_EnableIRQ(UARTE0_UART0_IRQn);
    
    
    
        // Configure LED-pins as outputs.
        LEDS_CONFIGURE(LEDS_MASK);
        if(NRF_UARTE0->EVENTS_RXSTARTED){
            LEDS_INVERT(1 << leds_list[1]);
        }
    
    
        while (true)
        {
        	NRF_UARTE0->TASKS_STARTTX;
        }
    }
    
Reply
  • Thank you both for you're response and you're hint with the static allocation of the buffers!

    Unfortunately the whole system still doesn't work for me. I have the DK connected to my PC and I see the COM Port in my device manger. I'm also able to connect the COM port to a terminal app (tera term and hterm) but I can't send or receive any data (I also tested with different PC's) :-(.

    Did the LED[3] switch off in your testsystem? Are you also using Pin 6 (TX) and 8 (RX)? Is there maybe a special driver I have to install? Or did you have to make any special configuration for the Segger chip? As IDE I'm using eclipse with gcc.

    Here's the updated code with TX and static buffers:

    #include <stdbool.h>
    #include <stdint.h>
    #include <string.h>
    #include "nrf_delay.h"
    #include "nrf_gpio.h"
    #include "boards.h"
    #include "nrf_uarte.h"
    
    const uint8_t leds_list[LEDS_NUMBER] = LEDS_LIST;
    
    void UARTE0_UART0_IRQHandler(){
    
        if(NRF_UARTE0->EVENTS_ENDRX){
            LEDS_INVERT(1 << leds_list[3]);
        }
    
    }
    
    
    int main(void)
    {
    
    	static uint8_t txBuffer[5] = {'h','e','l','l','o',};
    	static uint8_t rxBuffer[20] = {0};
    
        NRF_UARTE0->BAUDRATE = NRF_UARTE_BAUDRATE_9600;
        NRF_UARTE0->PSEL.TXD = TX_PIN_NUMBER;
        NRF_UARTE0->PSEL.RXD = RX_PIN_NUMBER;
        NRF_UARTE0->CONFIG = NRF_UARTE_HWFC_DISABLED;
        NRF_UARTE0->ENABLE = (UARTE_ENABLE_ENABLE_Enabled << UARTE_ENABLE_ENABLE_Pos);
    
        NRF_UARTE0->TXD.PTR = (uint32_t)((uint8_t *) txBuffer);
        NRF_UARTE0->TXD.MAXCNT = sizeof(txBuffer);
        NRF_UARTE0->TASKS_STARTTX = 0;
    
        NRF_UARTE0->RXD.PTR = (uint32_t)((uint8_t *) rxBuffer);
        NRF_UARTE0->RXD.MAXCNT = sizeof(rxBuffer);
        NRF_UARTE0->TASKS_STARTRX = 1;
    
    
        NRF_UARTE0->INTENCLR = 0xFFFFFFFF;
        NRF_UARTE0->INTENSET = NRF_UARTE_INT_ENDRX_MASK;
    
        NVIC_ClearPendingIRQ(UARTE0_UART0_IRQn);
        NVIC_SetPriority(UARTE0_UART0_IRQn, 1);
        NVIC_EnableIRQ(UARTE0_UART0_IRQn);
    
    
    
        // Configure LED-pins as outputs.
        LEDS_CONFIGURE(LEDS_MASK);
        if(NRF_UARTE0->EVENTS_RXSTARTED){
            LEDS_INVERT(1 << leds_list[1]);
        }
    
    
        while (true)
        {
        	NRF_UARTE0->TASKS_STARTTX;
        }
    }
    
Children
No Data
Related