1 /* 2 * Copyright (c) 2021 Jonathan Hahn 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #include <zephyr/kernel.h> 8 #include <zephyr/device.h> 9 #include <zephyr/devicetree.h> 10 #include <zephyr/drivers/uart.h> 11 12 #define UART_NODE1 DT_ALIAS(single_line_uart1) 13 #define UART_NODE2 DT_ALIAS(single_line_uart2) 14 15 const struct device *const sl_uart1 = DEVICE_DT_GET(UART_NODE1); 16 const struct device *const sl_uart2 = DEVICE_DT_GET(UART_NODE2); 17 main(void)18int main(void) 19 { 20 unsigned char recv; 21 22 if (!device_is_ready(sl_uart1) || !device_is_ready(sl_uart2)) { 23 printk("uart devices not ready\n"); 24 return 0; 25 } 26 27 while (true) { 28 29 uart_poll_out(sl_uart1, 'c'); 30 31 /* give the uarts some time to get the data through */ 32 k_sleep(K_MSEC(50)); 33 34 int ret = uart_poll_in(sl_uart2, &recv); 35 36 if (ret < 0) { 37 printk("Receiving failed. Error: %d", ret); 38 } else { 39 printk("Received %c\n", recv); 40 } 41 42 k_sleep(K_MSEC(2000)); 43 } 44 return 0; 45 } 46