Troubleshooting 'USART Device Not Ready' Error on AVR Microcontroller with Zephyr RTOS

hey guys, I am trying to set up USART communication on an AVR microcontroller running Zephyr RTOS to send data to an IoT cloud platform. I have configured the USART peripheral in the
prj.conf
prj.conf
file, created a Zephyr USART device binding in the device tree source file (
dts
dts
), and wrote an application to send data over USART. However, I am encountering an error stating
USART device not ready
USART device not ready
. I have verified the device tree source configuration to ensure proper USART peripheral settings, checked the pin configurations to match the hardware setup, and ensured the connections are correct. What could be causing this issue? @Middleware & OS
Solution:
Hey @Dtynin , I see you are talking about SPI, but if you're also working with USART and encountering the "USART device not ready" error, there are some common troubleshooting steps you can follow to resolve this. like Verifying that the USART node in your .dts file is correctly defined and matches your hardware setup, also ensure the compatible property is set correctly and that the USART pins (tx, rx, etc.) are properly assigned. Make sure that the necessary configurations for USART are enabled in your prj.conf file. This includes enabling the USART driver and setting any required parameters....
Jump to solution
8 Replies
Dtynin
Dtynin4mo ago
A successful outcome would involve the application running without the "USART device not ready" error and potentially transmitting data over the USART peripheral.
Solution
RED HAT
RED HAT4mo ago
Hey @Dtynin , I see you are talking about SPI, but if you're also working with USART and encountering the "USART device not ready" error, there are some common troubleshooting steps you can follow to resolve this. like Verifying that the USART node in your .dts file is correctly defined and matches your hardware setup, also ensure the compatible property is set correctly and that the USART pins (tx, rx, etc.) are properly assigned. Make sure that the necessary configurations for USART are enabled in your prj.conf file. This includes enabling the USART driver and setting any required parameters.
Enthernet Code
Enthernet Code4mo ago
@Dtynin check that the USART peripheral clock is enabled, Sometimes, the peripheral may not be ready because its clock is not enabled and Also ensure that the device binding in your code correctly refers to the USART node in your device tree. Use DEVICE_DT_GET with the correct node label.
Dark AI
Dark AI4mo ago
Yea, @Dtynin this is a code example to help illustrate how you can set up and check the USART device: device tree
&usart1 {
compatible = "st,stm32-usart";
current-speed = <115200>;
status = "okay";
pinctrl-0 = <&usart1_tx_pa9 &usart1_rx_pa10>;
pinctrl-names = "default";
};
&usart1 {
compatible = "st,stm32-usart";
current-speed = <115200>;
status = "okay";
pinctrl-0 = <&usart1_tx_pa9 &usart1_rx_pa10>;
pinctrl-names = "default";
};
prj.conf file:
CONFIG_SERIAL=y
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_UART_CONSOLE=y
CONFIG_SERIAL=y
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_UART_CONSOLE=y
Dark AI
Dark AI4mo ago
And finally the c code to test the above if they work
#include <zephyr.h>
#include <device.h>
#include <drivers/uart.h>
#include <logging/log.h>

LOG_MODULE_REGISTER(main);

#define UART_DEVICE_NODE DT_NODELABEL(usart1)

void main(void) {
const struct device *uart_dev = DEVICE_DT_GET(UART_DEVICE_NODE);

if (!device_is_ready(uart_dev)) {
LOG_ERR("USART device not ready");
return;
}

LOG_INF("USART device initialized successfully");

const char msg[] = "Hello, USART!\n";
uart_poll_out(uart_dev, msg[0]);

for (int i = 1; msg[i] != '\0'; i++) {
uart_poll_out(uart_dev, msg[i]);
}
}
#include <zephyr.h>
#include <device.h>
#include <drivers/uart.h>
#include <logging/log.h>

LOG_MODULE_REGISTER(main);

#define UART_DEVICE_NODE DT_NODELABEL(usart1)

void main(void) {
const struct device *uart_dev = DEVICE_DT_GET(UART_DEVICE_NODE);

if (!device_is_ready(uart_dev)) {
LOG_ERR("USART device not ready");
return;
}

LOG_INF("USART device initialized successfully");

const char msg[] = "Hello, USART!\n";
uart_poll_out(uart_dev, msg[0]);

for (int i = 1; msg[i] != '\0'; i++) {
uart_poll_out(uart_dev, msg[i]);
}
}
Dtynin
Dtynin4mo ago
Hey @RED HAT , thanks for the detailed troubleshooting steps! I'll make sure to verify the USART node in my
.dts
.dts
file and double-check the pin assignments. will also review the configurations in my
prj.conf
prj.conf
file to ensure everything is correctly enabled. Appreciate the help!
Dtynin
Dtynin4mo ago
Thanks for the tips @Enthernet Code, I'll make sure the USART clock is enabled and double-check the device binding with DEVICE_DT_GET. I appreciate 👍
Dtynin
Dtynin4mo ago
@Dark AI , Thanks for the example! I'll set up the device tree, prj.conf, and test code as you suggested. This should help a lot😇
Want results from more Discord servers?
Add your server