No UART Output on nRF52840 Dongle with Custom DT Overlay

Hello,

I am relatively new to embedded systems and currently developing a project using the nRF52840 Dongle and facing an issue with UART output. Despite configuring my setup as per the standard guidelines, I am not receiving any output from the UART. I am seeking assistance to resolve this issue.

Development Setup:

  • Board: nRF52840 Dongle
  • Environment: nRF Connect SDK with Zephyr OS
  • Peripherals: CP2102 USB-to-UART adapter, PCA9685 PWM controller
  • Connection: The CP2102 UART adapter is connected to the nRF52840 Dongle via jumper wires to the RX and TX pins.

Issue Description: The UART is configured to communicate at 115200 baud, with 8 data bits, no parity, 1 stop bit, and no flow control. However, when attempting to output log messages or data via printk, no output is observed on the connected serial console. The physical connections have been double-checked and appear to be correct.

Troubleshooting Steps Taken:

  • Verified the UART configuration in the code.
  • Ensured that the baud rate and settings of the serial console match the UART configuration.
  • Checked for correct physical connections between the dongle and the CP2102 adapter (cross-connection of RX and TX, shared ground).
  • Rebuilt the project with a clean configuration.

Attachments:

  1. main.c: Contains the main application code, including UART configuration and usage.
  2. nrf52840dongle_nrf52840.overlay: The device tree overlay used for the nRF52840 Dongle, defining the UART and PCA9685 configurations.
  3. prj.conf: The project configuration file outlining enabled features and relevant settings in Zephyr.

Given these details, I would appreciate any insights or suggestions you might have to resolve this issue. Specifically, I am looking to understand why the UART output is not functioning as expected despite seemingly correct configurations and whether there are any additional checks or configurations I should consider.

Thank you in advance for your assistance.

#include <zephyr/kernel.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/drivers/pwm.h>
#include <zephyr/drivers/uart.h>
#include <zephyr/logging/log.h>
#include <stdio.h>

#define LED0_NODE DT_ALIAS(led0)

// Adjust these values based on your servo's specifications
#define SERVO_MIN_PULSE_WIDTH_NS 1000000  // Minimum pulse width for the servo in nanoseconds (e.g., 1ms)
#define SERVO_MAX_PULSE_WIDTH_NS 2000000  // Maximum pulse width for the servo in nanoseconds (e.g., 2ms)
#define SERVO_PERIOD_NS          20000000 // Period of the servo signal in nanoseconds (e.g., 20ms)

static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios);

LOG_MODULE_REGISTER(main);

int main(void) {
    const struct device *pwm_dev;
    const struct device *uart_dev;
    struct uart_config uart_cfg;
    int pwm_set_ret;

    uart_dev = DEVICE_DT_GET(DT_NODELABEL(uart1));
    if (!device_is_ready(uart_dev)) {
        LOG_ERR("UART device not ready");
        return -1;
    }

    // Configure the UART device
    uart_cfg.baudrate = 115200;
    uart_cfg.parity = UART_CFG_PARITY_NONE;
    uart_cfg.stop_bits = UART_CFG_STOP_BITS_1;
    uart_cfg.data_bits = UART_CFG_DATA_BITS_8;
    uart_cfg.flow_ctrl = UART_CFG_FLOW_CTRL_NONE;

    if (uart_configure(uart_dev, &uart_cfg) < 0) {
        LOG_ERR("Failed to configure UART");
        return -1;
    }
    printk("UART device configured");


    printk("Starting MG996R Tower Pro Servo Control\n");

    if (!gpio_is_ready_dt(&led)) {
        printk("LED device not ready");
		return 0;
	}

	if (gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE) < 0) {
        printk("Failed to configure LED");
		return 0;
	}

    pwm_dev = DEVICE_DT_GET(DT_NODELABEL(pca9685));
    if (!device_is_ready(pwm_dev)) {
        printk("PWM device not ready");
        // return 0;
    }

    while (1) {
        k_sleep(K_SECONDS(2));
        gpio_pin_toggle_dt(&led);
        printk("LED toggled");

        // Rotate the servo to one end (e.g., 0 degrees)
        pwm_set_ret = pwm_set(pwm_dev, 0, SERVO_PERIOD_NS, SERVO_MIN_PULSE_WIDTH_NS, 0);
        if (pwm_set_ret) {
            printk("Error setting PWM: %d\n", pwm_set_ret);
            // return 0;
        }
        k_sleep(K_SECONDS(2));

        // Rotate the servo to the other end (e.g., 180 degrees)
        pwm_set_ret = pwm_set(pwm_dev, 0, SERVO_PERIOD_NS, SERVO_MAX_PULSE_WIDTH_NS, 0);
        if (pwm_set_ret) {
            printk("Error setting PWM: %d\n", pwm_set_ret);
            // return 0;
        }
        k_sleep(K_SECONDS(2));
    }
}

3531.nrf52840dongle_nrf52840.overlay

2045.prj.conf

Parents Reply Children
No Data
Related