Hi everyone,
I have a problem when I tried to configure UART (baudrate, parity, data_bits, stop_bits, flow_ctrl).
I upload my project:
#include "myuart.h"
#include <zephyr/sys/printk.h>
/* 1000 msec = 1 sec */
#define SLEEP_TIME_MS 1000
/* Define the size of the receive buffer */
#define DATA_LENGTH 15
#define DATA_COUNT 5
#define TOTAL_BUFFER_SIZE (DATA_LENGTH * DATA_COUNT) // 90 byte (18 x 5)
/* Define the receiving timeout period */
#define RECEIVE_TIMEOUT 100
//configure GPIO UART for NRF54L15
static const struct device *uart0_dev = DEVICE_DT_GET(DT_NODELABEL(uart30));
static const struct device *uart1_dev = DEVICE_DT_GET(DT_NODELABEL(uart20));
/* Cấu hình UART (baudrate, parity, v.v.) */
static struct uart_config uart_cfg = {
.baudrate = 115200,
.parity = UART_CFG_PARITY_NONE,
.data_bits = UART_CFG_DATA_BITS_8,
.stop_bits = UART_CFG_STOP_BITS_1,
.flow_ctrl = UART_CFG_FLOW_CTRL_NONE,
};
void myuart_init(void)
{
int ret;
if (!device_is_ready(uart0_dev)) {
printk("UART30 device not ready\n");
}
if (!device_is_ready(uart1_dev)) {
printk("UART20 device not ready\n");
}
/* Configure UART0, UART1 */
ret = uart_configure(uart0_dev, &uart_cfg);
if (ret) {
printk("Failed to configure UART30, err %d\n", ret);
}
ret = uart_configure(uart1_dev, &uart_cfg);
if (ret) {
printk("Failed to configure UART20, err %d\n", ret);
}
/* Gán callback cho UART0 */
ret = uart_callback_set(uart0_dev, uart_cb, &uart_data_instance);
if (ret) {
printk("Failed to set UART20 callback, err %d\n", ret);
return;
}
ret = uart_rx_enable(uart0_dev, rx_buf, sizeof(rx_buf), RECEIVE_TIMEOUT);
if (ret) {
printk("ERROR RX for UART20: %d\n", ret);
return;
}
printk("uart_init Done!\n");
}
file .dts:
&uart20 {
compatible = "nordic,nrf-uarte";
status = "okay";
current-speed = <115200>;
pinctrl-0 = <&uart20_default>;
pinctrl-names = "default";
};
&uart30 {
compatible = "nordic,nrf-uarte";
status = "okay";
current-speed = <115200>;
pinctrl-0 = <&uart30_default>;
pinctrl-names = "default";
};
file .dtsi:
&pinctrl {
uart20_default: uart20_default {
group1 {
psels = <NRF_PSEL(UART_TX, 1, 4)>;
};
group2 {
psels = <NRF_PSEL(UART_RX, 1, 5)>;
bias-pull-up;
};
};
uart30_default: uart30_default {
group1 {
psels = <NRF_PSEL(UART_TX, 0, 0)>;
};
group2 {
psels = <NRF_PSEL(UART_RX, 0, 1)>;
bias-pull-up;
};
};
};
but, when I flashed code in board, my error:
"
Failed to configure UART20, err -134
"
Can you help me for this problems, please?