This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

UART problem NRF9160(Icarus) to ESP8266

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));

	}
}

Parents
  • Check out the LPUART sample and see if you're able to communicate with the ESP8266 board.

    Best regards,

    Simon

  • This sample just print out: "E: could not get GPIO Device Binding" and then it ends. if I set  CONFIG_NRF_SW_LPUART_INT_DRIVEN=y, then it reboots everytime after the same error message. How can I send anything with that sample? 

    Best regards,

    Tim

  • I just tested it with NCS v1.6.0 and it worked fine. I did the following changes to enable logging:

    https://github.com/nrfconnect/sdk-nrf/compare/nrfconnect:7a076c2...simon-iversen:060b624 

    I connected P0.10 to P0.11 and P0.12 to P0.13, programmed it and got the following otuput:

    *** Booting Zephyr OS build v2.6.0-rc1-ncs1  ***
    [00:00:01.349,731] <inf> app: Tx sent 5 bytes
    [00:00:01.350,433] <inf> app: Received data 5 bytes
    [00:00:01.850,372] <inf> app: Received data 1 bytes
    [00:00:01.950,439] <inf> app: Tx sent 5 bytes
    [00:00:01.951,141] <inf> app: Received data 5 bytes
    [00:00:02.451,049] <inf> app: Received data 1 bytes
    [00:00:02.551,147] <inf> app: Tx sent 5 bytes
    [00:00:02.551,818] <inf> app: Received data 5 bytes
    [00:00:03.051,788] <inf> app: Received data 1 bytes
    [00:00:03.151,855] <inf> app: Tx sent 5 bytes
    [00:00:03.152,557] <inf> app: Received data 5 bytes
    [00:00:03.652,465] <inf> app: Received data 1 bytes
    [00:00:03.752,593] <inf> app: Tx sent 5 bytes
    [00:00:03.753,265] <inf> app: Received data 5 bytes
    [00:00:04.253,204] <inf> app: Received data 1 bytes
    [00:00:04.353,302] <inf> app: Tx sent 5 bytes

    Try the same and see if you're able to get it to work. By the way, the sample does not support the board nrf9160dk_nrf9160ns, so you have to add it yourself here https://github.com/nrfconnect/sdk-nrf/tree/v1.6.0/samples/peripheral/lpuart/boards.

    Best regards,

    Simon

  • I just tested it with your suggested changes and with nRF Connect SDK v1.6.0-rc2. I am using the icarus Board and created the following two documents within lpuart/Boards to get Board support:

    /* actinius_icarus_ns.overlay */
    
    &uart1 {
    	status = "okay";
    
    	current-speed = <115200>;
    	tx-pin = <24>;
    	rx-pin = <23>;
    	
    	lpuart: nrf-sw-lpuart {
                    compatible = "nordic,nrf-sw-lpuart";
                    status = "okay";
                    label = "LPUART";
                    req-pin = <46>;
                    rdy-pin = <47>;
            };
    };
    
    &gpiote {
    	interrupts = <13 NRF_DEFAULT_IRQ_PRIORITY>;
    };
    ## actinius_icarus_ns.conf
    
    CONFIG_UART_1_ASYNC=y
    CONFIG_UART_1_INTERRUPT_DRIVEN=n
    CONFIG_UART_1_NRF_HW_ASYNC=y
    CONFIG_UART_1_NRF_HW_ASYNC_TIMER=2
    CONFIG_NRFX_TIMER2=y

    Unfortunately I get the following outprint after flashing:

    E: Could not get GPIO Device Binding
    *** Booting Zephyr OS build v2.6.0-rc1-ncs1-rc1  ***
    Flash regions           Domain          Permissions
    00 01 0x00000 0x10000   Secure          rwxl
    02 31 0x10000 0x100000  Non-Secure      rwxl
    
    Non-secure callable region 0 placed in flash region 1 with size 32.
    
    SRAM region             Domain          Permissions
    00 07 0x00000 0x10000   Secure          rwxl
    08 31 0x10000 0x40000   Non-Secure      rwxl
    
    Peripheral              Domain          Status
    00 NRF_P0               Non-Secure      OK
    01 NRF_CLOCK            Non-Secure      OK
    02 NRF_RTC0             Non-Secure      OK
    03 NRF_RTC1             Non-Secure      OK
    04 NRF_NVMC             Non-Secure      OK
    05 NRF_UARTE1           Non-Secure      OK
    06 NRF_UARTE2           Secure          SKIP
    07 NRF_TWIM2            Non-Secure      OK
    08 NRF_SPIM3            Non-Secure      OK
    09 NRF_TIMER0           Non-Secure      OK
    10 NRF_TIMER1           Non-Secure      OK
    11 NRF_TIMER2           Non-Secure      OK
    12 NRF_SAADC            Non-Secure      OK
    13 NRF_PWM0             Non-Secure      OK
    14 NRF_PWM1             Non-Secure      OK
    15 NRF_PWM2             Non-Secure      OK
    16 NRF_PWM3             Non-Secure      OK
    17 NRF_WDT              Non-Secure      OK
    18 NRF_IPC              Non-Secure      OK
    19 NRF_VMC              Non-Secure      OK
    20 NRF_FPU              Non-Secure      OK
    21 NRF_EGU1             Non-Secure      OK
    22 NRF_EGU2             Non-Secure      OK
    23 NRF_DPPIC            Non-Secure      OK
    24 NRF_REGULATORS       Non-Secure      OK
    25 NRF_PDM              Non-Secure      OK
    26 NRF_I2S              Non-Secure      OK
    27 NRF_GPIOTE1          Non-Secure      OK
    
    SPM: NS image at 0x10000
    SPM: NS MSP at 0x20011838
    SPM: NS reset vector at 0x16111
    SPM: prepare to jump to Non-Secure image.
    ASSERTION FAIL [i < 8] @ WEST_TOPDIR/nrf/drivers/serial/uart_nrf_sw_lpuart.c:412
            Used channel not found
    [00:00:00.000,244] <err> board_control: Could not get GPIO Device Binding
    [00:00:00.012,176] <err> os: r0/a1:  0x00000004  r1/a2:  0x0000019c  r2/a3:  0x0                                                                                                             0000001
    [00:00:00.012,207] <err> os: r3/a4:  0x00000018 r12/ip:  0x00004000 r14/lr:  0x0                                                                                                             001a4e7
    [00:00:00.012,207] <err> os:  xpsr:  0x41000000
    [00:00:00.012,237] <err> os: Faulting instruction address (r15/pc): 0x000210b8
    [00:00:00.012,268] <err> os: >>> ZEPHYR FATAL ERROR 4: Kernel panic on CPU 0
    [00:00:00.012,268] <err> os: Current thread: 0x20010460 (unknown)
    ▒E: Could not get GPIO Device Binding Resetting system
    

    Best regards,

    Tim

Reply
  • I just tested it with your suggested changes and with nRF Connect SDK v1.6.0-rc2. I am using the icarus Board and created the following two documents within lpuart/Boards to get Board support:

    /* actinius_icarus_ns.overlay */
    
    &uart1 {
    	status = "okay";
    
    	current-speed = <115200>;
    	tx-pin = <24>;
    	rx-pin = <23>;
    	
    	lpuart: nrf-sw-lpuart {
                    compatible = "nordic,nrf-sw-lpuart";
                    status = "okay";
                    label = "LPUART";
                    req-pin = <46>;
                    rdy-pin = <47>;
            };
    };
    
    &gpiote {
    	interrupts = <13 NRF_DEFAULT_IRQ_PRIORITY>;
    };
    ## actinius_icarus_ns.conf
    
    CONFIG_UART_1_ASYNC=y
    CONFIG_UART_1_INTERRUPT_DRIVEN=n
    CONFIG_UART_1_NRF_HW_ASYNC=y
    CONFIG_UART_1_NRF_HW_ASYNC_TIMER=2
    CONFIG_NRFX_TIMER2=y

    Unfortunately I get the following outprint after flashing:

    E: Could not get GPIO Device Binding
    *** Booting Zephyr OS build v2.6.0-rc1-ncs1-rc1  ***
    Flash regions           Domain          Permissions
    00 01 0x00000 0x10000   Secure          rwxl
    02 31 0x10000 0x100000  Non-Secure      rwxl
    
    Non-secure callable region 0 placed in flash region 1 with size 32.
    
    SRAM region             Domain          Permissions
    00 07 0x00000 0x10000   Secure          rwxl
    08 31 0x10000 0x40000   Non-Secure      rwxl
    
    Peripheral              Domain          Status
    00 NRF_P0               Non-Secure      OK
    01 NRF_CLOCK            Non-Secure      OK
    02 NRF_RTC0             Non-Secure      OK
    03 NRF_RTC1             Non-Secure      OK
    04 NRF_NVMC             Non-Secure      OK
    05 NRF_UARTE1           Non-Secure      OK
    06 NRF_UARTE2           Secure          SKIP
    07 NRF_TWIM2            Non-Secure      OK
    08 NRF_SPIM3            Non-Secure      OK
    09 NRF_TIMER0           Non-Secure      OK
    10 NRF_TIMER1           Non-Secure      OK
    11 NRF_TIMER2           Non-Secure      OK
    12 NRF_SAADC            Non-Secure      OK
    13 NRF_PWM0             Non-Secure      OK
    14 NRF_PWM1             Non-Secure      OK
    15 NRF_PWM2             Non-Secure      OK
    16 NRF_PWM3             Non-Secure      OK
    17 NRF_WDT              Non-Secure      OK
    18 NRF_IPC              Non-Secure      OK
    19 NRF_VMC              Non-Secure      OK
    20 NRF_FPU              Non-Secure      OK
    21 NRF_EGU1             Non-Secure      OK
    22 NRF_EGU2             Non-Secure      OK
    23 NRF_DPPIC            Non-Secure      OK
    24 NRF_REGULATORS       Non-Secure      OK
    25 NRF_PDM              Non-Secure      OK
    26 NRF_I2S              Non-Secure      OK
    27 NRF_GPIOTE1          Non-Secure      OK
    
    SPM: NS image at 0x10000
    SPM: NS MSP at 0x20011838
    SPM: NS reset vector at 0x16111
    SPM: prepare to jump to Non-Secure image.
    ASSERTION FAIL [i < 8] @ WEST_TOPDIR/nrf/drivers/serial/uart_nrf_sw_lpuart.c:412
            Used channel not found
    [00:00:00.000,244] <err> board_control: Could not get GPIO Device Binding
    [00:00:00.012,176] <err> os: r0/a1:  0x00000004  r1/a2:  0x0000019c  r2/a3:  0x0                                                                                                             0000001
    [00:00:00.012,207] <err> os: r3/a4:  0x00000018 r12/ip:  0x00004000 r14/lr:  0x0                                                                                                             001a4e7
    [00:00:00.012,207] <err> os:  xpsr:  0x41000000
    [00:00:00.012,237] <err> os: Faulting instruction address (r15/pc): 0x000210b8
    [00:00:00.012,268] <err> os: >>> ZEPHYR FATAL ERROR 4: Kernel panic on CPU 0
    [00:00:00.012,268] <err> os: Current thread: 0x20010460 (unknown)
    ▒E: Could not get GPIO Device Binding Resetting system
    

    Best regards,

    Tim

Children
Related