Hi,
just getting started with nRF development and completed the 'nRF Connect SDK Fundamentals' course. I have the latest SDK and everything as recommended in the course.
Now, I am trying to figure out how to make UART communication work between two nRF52DK boards. The aim of this exercise was just to learn more about using the SDK. The end goal is actually to interface with some TMC stepper motor driver using UART. This should be a trivial exercise which I have been able to do with a few other microcontrollers, but I can't figure out why I can't get it to work with the nRFs.
Here is my code:
#include <zephyr/kernel.h>
#include <zephyr/device.h>
#include <zephyr/devicetree.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/drivers/uart.h>
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(nRF_TMC_driver);
#define TRANSMITTER 1
#define SLEEP_TIME_MS 1000
#define RX_BUFF_SIZE 2
#define RX_TIMEOUT 100
const struct device *uart = DEVICE_DT_GET(DT_NODELABEL(uart0));
static uint8_t rx_buf[RX_BUFF_SIZE] = {0};
static void uart_cb(const struct device *dev, struct uart_event *evt, void *user_data)
{
LOG_INF("evt->type %d", evt->type);
switch (evt->type)
{
case UART_TX_DONE:
LOG_INF("TX successful");
break;
case UART_RX_RDY:
LOG_INF("Received data %d bytes", evt->data.rx.len);
break;
case UART_RX_DISABLED:
uart_rx_enable(dev, rx_buf, sizeof(rx_buf), RX_TIMEOUT);
break;
case UART_RX_BUF_REQUEST:
uint8_t ret = uart_rx_buf_rsp(dev, rx_buf, sizeof(rx_buf));
LOG_INF("%d", ret);
break;
default:
break;
}
}
int main(void)
{
int ret;
if (!device_is_ready(uart)) {
LOG_INF("UART device not ready\r\n");
return 1;
}
ret = uart_callback_set(uart, uart_cb, NULL);
__ASSERT(ret == 0, "Failed to set callback");
uart_rx_disable(uart);
uart_rx_enable(uart, rx_buf, sizeof(rx_buf), RX_TIMEOUT);
while (1) {
#if TRANSMITTER
static uint8_t i = 0;
LOG_INF("Transmitting %d", i);
ret = uart_tx(uart, &i, 1, SYS_FOREVER_US);
i++;
#endif
k_msleep(SLEEP_TIME_MS);
}
}
I simply change the macro 'TRANSMITTER' to only have one of the two boards transmit data, the rest is the same.
Here is my prj.conf:
CONFIG_SERIAL=y CONFIG_UART_ASYNC_API=y CONFIG_UART_CONSOLE=n CONFIG_USE_SEGGER_RTT=y CONFIG_LOG_BACKEND_RTT=y CONFIG_RTT_CONSOLE=y CONFIG_LOG=y
The thought is to use UART for board-to-board communication and RTT for logging to my computer. I am using the default device tree overlay 'nrf52dk_nrf52832.dts' so flow control should be disabled. I haven't tried connecting RTS and CTS between the boards since the TMC drivers that I will be working with later on do not have those (I think...).
This is how I have connected the boards.

I appreciate any guidance or suggestions you may have!