Hello,
at the moment I am trying to get the NRF9160 Icarus Board to communicate with an ESP8266 Board within serial modem mode. I just need to send some AT commands through UART but I don't get any answer from the ESP8266. The communication with the ESP8266 works fine, if I attache it to my PC and using Putty. I can only get the first message printed out through the Icarus Board, if I reset the ESP8266 at the right time. I am using the exact same configuration (data, stop, parity bit) as Putty and I am always sending the carriage return and line feed at the end of my messages but the ESP still won't answer. Can you please have a look on my code so far?
//actinius_icarus_common.dts &uart1 { status = "okay"; current-speed = <115200>; tx-pin = <24>; rx-pin = <23>; label = "mainuart"; };
//prj.conf CONFIG_UART_INTERRUPT_DRIVEN=y CONFIG_UART_ASYNC_API=y CONFIG_TRUSTED_EXECUTION_NONSECURE=y CONFIG_UART_INTERRUPT_DRIVEN=y CONFIG_MAIN_STACK_SIZE=4096 CONFIG_BSD_LIBRARY_TRACE_ENABLED=n
//main.c #include <zephyr.h> #include <sys/printk.h> #include <drivers/uart.h> #include <string.h> static K_FIFO_DEFINE(fifo_uart_tx_data); static K_FIFO_DEFINE(fifo_uart_rx_data); static uint8_t uart_buf[1024]; struct uart_data_t { void *fifo_reserved; uint8_t data[1024]; uint16_t len; }; const struct uart_config uart_cfg = { .baudrate = 115200, .parity = UART_CFG_PARITY_NONE, .stop_bits = UART_CFG_STOP_BITS_1, .data_bits = UART_CFG_DATA_BITS_8, .flow_ctrl = UART_CFG_FLOW_CTRL_NONE, }; const struct device *uart_dev; static void uart_irq_handler(const struct device *x, void *context) { uint8_t buf[] = {1, 2, 3, 4, 5}; if (uart_irq_tx_ready(x)) { (void)uart_fifo_fill(x, buf, sizeof(buf)); uart_irq_tx_disable(x); } if (uart_irq_rx_ready(x)) { uint8_t buf[10]; int len = uart_fifo_read(x, buf, sizeof(buf)); printk("Received data is:%s\r\n", buf); if (buf == '\r') { printk("carriage Return"); } if (buf == '\n') { printk("LineFeed"); } if (len) { printk("read %d bytes\n", len); } } } void uart_sendCOM(const struct device *x, uint8_t *Cont) { uint16_t len = strlen(Cont); uart_fifo_fill(x, Cont,len ); uart_irq_tx_enable(x); } void main(void) { uart_dev = device_get_binding("mainuart"); if (!uart_dev) { printk("error\r\n"); } bool ret; ret = uart_configure(uart_dev, &uart_cfg); if (ret != 0) { printk("UART can not be configured!\n"); } uart_irq_rx_disable(uart_dev); uart_irq_tx_disable(uart_dev); uart_irq_callback_set(uart_dev, uart_irq_handler); // Set UART interrupt callback uart_irq_rx_enable(uart_dev); uart_irq_tx_enable(uart_dev); k_sleep(K_MSEC(100)); printk("UART loopback start!\n"); while (1) { printk("SendingAT..... \n"); uart_sendCOM(uart_dev, "AT\r\n"); k_sleep(K_MSEC(5000)); } }