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

SDKv1.5.1 Blinky example with UART

Dear Nordic support,

i'm evaluating the Nordic nRF52840_Dongle with the SDK 1.5.1, inlucing Zephyr etc. I could successfully compile and load the Blinky-example (..\ncs\v1.5.1\zephyr\samples\basic\blinky\build_nrf52840dongle_nrf52840) and manipulated it.

Now i am really struggeling to add a UART (a real UART, no CDC-USB) connection to the dongle. I promise i've read so many documentation (Zephyr, K-Config, Device-Tree, Nordic-SDK...). But i can't find answers...

---

1.) On which pins at the dongle, can i map the UART RX and TX pins?! Normally on a microcontroller i have a bunch of options, in the Nordic docs it looks like i can map them anywhere, can I? Precisely this configuration is feasible

zephyr.dts --

...

        uart0: uart@40002000 {
            reg = < 0x40002000 0x1000 >;
            interrupts = < 0x2 0x1 >;
            status = "okay";
            label = "UART_0";
            compatible = "nordic,nrf-uarte";
            current-speed = < 0x1c200 >;
            tx-pin = < 0x1f >;
            rx-pin = < 0x1d >;
            rts-pin = < 0x00 >;
            cts-pin = < 0x00 >;

...

2.) In the docs and even in the video the pins are numbered like "30", "31" and so on. But the in ref-maunal and the schematic there ist port number AND the pin number , e.g 0.12, 1.15, how do i address 1.15, when i want to used it as a UART pin in the config overlay file?

3.) In the picture below, there is my code of the blinky example, including my attemps of using the UART via the zephyr-API. The Problem is, that the "device_get_binding" - function returns a NULL-pointer. I have no idea why. 

Thanks a lot.

Sören

Parents
  • Hi Sören,

    1.) On which pins at the dongle, can i map the UART RX and TX pins?! Normally on a microcontroller i have a bunch of options, in the Nordic docs it looks like i can map them anywhere, can I? Precisely this configuration is feasible

    Any digital GPIO pin can be used for UART. See Pin assignments.

    2.) In the docs and even in the video the pins are numbered like "30", "31" and so on. But the in ref-maunal and the schematic there ist port number AND the pin number , e.g 0.12, 1.15, how do i address 1.15, when i want to used it as a UART pin in the config overlay file?

    The pin numbers you provide is x if using P0.x and y + 32 if using P1.y.

    3.) In the picture below, there is my code of the blinky example, including my attemps of using the UART via the zephyr-API. The Problem is, that the "device_get_binding" - function returns a NULL-pointer. I have no idea why. 

    Have you enabled UART0 in prj.conf? You can refer to a sample that use UART, for instance nrf\samples\bluetooth\peripheral_uart\

    Einar

  • Hi Einar,

    thanks,

    1. and 2. are clear now.

    After i changed the proj.conf to:

    CONFIG_GPIO=y
    CONFIG_UART_INTERRUPT_DRIVEN=y
    CONFIG_SERIAL=y
    CONFIG_UART_ASYNC_API=y

    there is an address connected to the handler, but there is still now traffic on the pins (i used tx-pin = <0x14> and rx-pin = <0x18>). I've checked this with a logic analyser.

    As i understand it, i only need the uart_tx() function to send something, am i right? Or is there another config that i have to set.

    developer.nordicsemi.com/.../uart.html

    ==edit==

    ret = uart_tx(uart_0_handle, &message, sizeof(message), SYS_FOREVER_MS );

    returns -35 -> -ENOTSUP: If driver does not support getting current configuration. 

    Why the driver is not supported? Which driver is supported?

    Thanks,

    Sören

  • Hi Sören,

    I am sorry for the delay. Have you made any progress on this? If not, perhaps you can upload your project here so I can look at it and try to build it on my side?

    SoerenBirth said:
    But, why do i have to copy a file prj.overlay in the project with the same content as the zephyr.dts file???

    You do not, I did not spot that it was in there before. All should be good in this regard then (the prj.overlay is a overlay to the dts, in much the same as the prj.conf is a overlay for the Kconfig configuration, though it is unfortunately not well documented).

  • 2437.blinky.rar

    Hi Einar,

    no i did not manage it. But here is my project.

    Thank you,

    Sören

  • Hi,

    I have attached a modified project that is working here. This works both on the DK and dongle. I tested with the default board file (zephyr\boards\arm\nrf52840dongle_nrf52840\nrf52840dongle_nrf52840.dts) with the Tx pin being P0.20, but using another pin should be no problem.

    Code:

    #include <zephyr.h>
    #include <device.h>
    #include <soc.h>
    #include <devicetree.h>
    #include <drivers/gpio.h>
    #include <drivers/uart.h>
    
    
    /* 1000 msec = 1 sec */
    #define SLEEP_TIME_MS 1000
    
    /* The devicetree node identifier for the "led0" alias. */
    #define LED0_NODE DT_ALIAS(led0)
    
    #define LED0 DT_GPIO_LABEL(LED0_NODE, gpios)
    #define PIN0 DT_GPIO_PIN(LED0_NODE, gpios)
    #define FLAGS0 DT_GPIO_FLAGS(LED0_NODE, gpios)
    
    #define LED1_NODE DT_ALIAS(led1)
    #define LED1 DT_GPIO_LABEL(LED1_NODE, gpios)
    #define PIN1 DT_GPIO_PIN(LED1_NODE, gpios)
    #define FLAGS1 DT_GPIO_FLAGS(LED1_NODE, gpios)
    
    #define UART0_NODE DT_NODELABEL(uart0)
    #define UART0 DT_LABEL(UART0_NODE)
    #define UART_LABEL		DT_LABEL(DT_NODELABEL(uart0))
    
    
    void main(void)
    {
    	const struct device *green_led_handle;
    	const struct device *red_led_handle;
    	const struct device *uart_0_handle;
    	bool led_is_on = true;
    	volatile int ret;
    	const uint8_t message[] = "Hello World! \n\r";
    
    	green_led_handle = device_get_binding(LED0);
    	if (green_led_handle == NULL)
    	{
    		return;
    	}
    
    	red_led_handle = device_get_binding(LED1);
    	if (red_led_handle == NULL)
    	{
    		return;
    	}
    
    	uart_0_handle = device_get_binding(UART_LABEL);
    
    	if (!uart_0_handle) {
    		return;
    	}
    
    	ret = gpio_pin_configure(green_led_handle, PIN0, GPIO_OUTPUT_ACTIVE | FLAGS0);
    	if (ret < 0)
    	{
    		return;
    	}
    
    	ret = gpio_pin_configure(red_led_handle, PIN1, GPIO_OUTPUT_ACTIVE | FLAGS1);
    	if (ret < 0)
    	{
    		return;
    	}
    
    	while (1)
    	{
    		gpio_pin_set(green_led_handle, PIN0, (int)led_is_on);
    		led_is_on = !led_is_on;
    		gpio_pin_set(red_led_handle, PIN1, (int)led_is_on);
    		ret = uart_tx(uart_0_handle, message, sizeof(message), 100);
    		k_msleep(SLEEP_TIME_MS);
    	}
    }

    Config:

    8015.prj.conf

    Logic analyzer plot:

  • Thanks Einar,

    The key was just one line in the prj.conf file

    after i deleted CONFIG_UART_INTERRUPT_DRIVEN it immediately worked!

    The next question will be, how do i get the interrupt based transfer started.

    Best regards

    Sören

  • Hi Sören,

    You cannot use uart_tx() with CONFIG_UART_INTERRUPT_DRIVEN, as that is only supported by the newer CONFIG_UART_ASYNC_API. Note that CONFIG_UART_ASYNC_API is also interrupt driven so there are typically no reason to use the older API unless you want to be conservative.

Reply Children
No Data
Related