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

Transmitting data over UART_2 to external sensors

Hi Dev Team,

I have been trying to send data across from my nRF9160DK board to an external sensor via RS-485. For this, I have a TTL_RS485 converter in between.

To start off with, I just want to send a string and receive it on an external debugger to check my UART communication. I am using UART_2 and I am attaching my nrf9160dk_nrf9160ns.overlay file here. The wiring has been done based on uart_2 configuration. 

/* Needed to get NRF_PWMn defined. */


/ {
	model = "Nordic nRF9160 DK NRF9160";
	compatible = "nordic,nrf9160-dk-nrf9160";

	chosen {
		zephyr,console = &uart0;
		zephyr,shell-uart = &uart0;
		zephyr,uart-mcumgr = &uart0;
	};
};


&pwm1 {
	status = "okay";
};

&pwm2 {
	status = "okay";
};

&pwm3 {
	status = "okay";
};


&uart1 {
	current-speed = <9600>;
	status = "okay";
	tx-pin = <12>;
	rx-pin = <13>;
	rts-pin = <14>;
	cts-pin = <15>;
};



&uart2 {
	status = "okay";
	current-speed = <9600>;
	tx-pin = <10>;
	rx-pin = <11>;
	rts-pin = <16>;
	cts-pin = <17>;
};

The same is in the SPM folder as nrf9160dk_nrf9160.overlay file. 

The basic UART example in the master branch provides the structure to receive data from UART. Is there any particular example to send the data from the UART ?.

I tried following this thread : https://devzone.nordicsemi.com/f/nordic-q-a/44788/nrf9160-dk-send-receive-data-from-uart1/179149#179149  , but I get an error while trying to implement that code. The error I get is in Line 24 where k_fifo_get is defined. Is there any way to fix this issue ?

Is there any other example that shows how to transmit the strings externally through a UART (UART_2 in my case).

Regards,

Adeel.

  • Hi,

    As an addition, I am facing issues to communicate anything externally through UART_2. I tried 2 examples : C:\Users\adeel\ncs\v1.3.0\zephyr\tests\drivers\uart\uart_basic_api and the simple UART example in the master branch.

    All I am trying to do for now is to send a character string out to receive it on an external debugger connected to my sensor.

    Whatever changes I do and try to send , I can only see it in my LTE Link monitor i.e: connected to UART_0 by default I presume. 

    Can any of the above examples mentioned be tuned in order to send the data out (through UART_2)? I would really request a heads up on this :). 

  • Hello, Adeel!

    I'm looking into the issue. Have you tried to observe the pins with a logic analyzer? An could you provide your prj.conf aswell? 

    When it comes to examples you can have a look at the project I've attached below. It is configured to send commands over UART2. It's based on Yusukes code from this thread.
    5148.hello_world.zip

    And I've added the following to the overlay in SPM:

    &uart2 {
    	status = "okay";
    	current-speed = <115200>;
    	tx-pin = <1>;
    	rx-pin = <0>;
    	rts-pin = <14>;
    	cts-pin = <15>;
    };
    
    &uart1 {
    	status = "disabled";
    };

    Best regards,
    Carl Richard

  • Hi Carl,

    I will have to look if I can get a logic analyzer to check it out. Any other way to check it out in the software ?

    My prj.conf file:

    CONFIG_NEWLIB_LIBC=y
    CONFIG_LIBLIGHTMODBUS=y
    
    CONFIG_GPIO=y
    
    CONFIG_SERIAL=y
    CONFIG_TRUSTED_EXECUTION_NONSECURE=y
    CONFIG_UART_INTERRUPT_DRIVEN=y
    CONFIG_MAIN_STACK_SIZE=4096
    
    CONFIG_COMPILER_OPT="-DNRFX_UARTE_ENABLED=1 -DNRFX_UARTE0_ENABLED=1"
    CONFIG_BSD_LIBRARY_TRACE_ENABLED=n

    I also see in my devicetree_unfixed.h that the UART_2 is configured by my external pins. 

    /* Generic property macros: */
    #define DT_N_S_soc_S_peripheral_40000000_S_uart_a000_P_reg {40960 /* 0xa000 */, 4096 /* 0x1000 */}
    #define DT_N_S_soc_S_peripheral_40000000_S_uart_a000_P_reg_IDX_0 40960
    #define DT_N_S_soc_S_peripheral_40000000_S_uart_a000_P_reg_IDX_1 4096
    #define DT_N_S_soc_S_peripheral_40000000_S_uart_a000_P_reg_EXISTS 1
    #define DT_N_S_soc_S_peripheral_40000000_S_uart_a000_P_interrupts {10 /* 0xa */, 1 /* 0x1 */}
    #define DT_N_S_soc_S_peripheral_40000000_S_uart_a000_P_interrupts_IDX_0 10
    #define DT_N_S_soc_S_peripheral_40000000_S_uart_a000_P_interrupts_IDX_1 1
    #define DT_N_S_soc_S_peripheral_40000000_S_uart_a000_P_interrupts_EXISTS 1
    #define DT_N_S_soc_S_peripheral_40000000_S_uart_a000_P_hw_flow_control 0
    #define DT_N_S_soc_S_peripheral_40000000_S_uart_a000_P_hw_flow_control_EXISTS 1
    #define DT_N_S_soc_S_peripheral_40000000_S_uart_a000_P_tx_pin 10
    #define DT_N_S_soc_S_peripheral_40000000_S_uart_a000_P_tx_pin_EXISTS 1
    #define DT_N_S_soc_S_peripheral_40000000_S_uart_a000_P_rx_pin 11
    #define DT_N_S_soc_S_peripheral_40000000_S_uart_a000_P_rx_pin_EXISTS 1
    #define DT_N_S_soc_S_peripheral_40000000_S_uart_a000_P_rts_pin 16
    #define DT_N_S_soc_S_peripheral_40000000_S_uart_a000_P_rts_pin_EXISTS 1
    #define DT_N_S_soc_S_peripheral_40000000_S_uart_a000_P_cts_pin 17
    #define DT_N_S_soc_S_peripheral_40000000_S_uart_a000_P_cts_pin_EXISTS 1
    #define DT_N_S_soc_S_peripheral_40000000_S_uart_a000_P_current_speed 9600
    #define DT_N_S_soc_S_peripheral_40000000_S_uart_a000_P_current_speed_EXISTS 1
    #define DT_N_S_soc_S_peripheral_40000000_S_uart_a000_P_label "UART_2"
    #define DT_N_S_soc_S_peripheral_40000000_S_uart_a000_P_label_EXISTS 1
    #define DT_N_S_soc_S_peripheral_40000000_S_uart_a000_P_status "okay"
    #define DT_N_S_soc_S_peripheral_40000000_S_uart_a000_P_status_ENUM_IDX 1
    #define DT_N_S_soc_S_peripheral_40000000_S_uart_a000_P_status_EXISTS 1
    #define DT_N_S_soc_S_peripheral_40000000_S_uart_a000_P_compatible {"nordic,nrf-uarte"}
    #define DT_N_S_soc_S_peripheral_40000000_S_uart_a000_P_compatible_IDX_0 "nordic,nrf-uarte"
    #define DT_N_S_soc_S_peripheral_40000000_S_uart_a000_P_compatible_LEN 1
    #define DT_N_S_soc_S_peripheral_40000000_S_uart_a000_P_compatible_EXISTS 1

    So, I presume that I have correctly configured my UART_2 (or) anything else might be required ? 

    Regards,

    Adeel.

  • Hi Carl,

    I tried running your example file with a slight modification in the pins and baud rate (10,11,16,17 respectively with 9600 baud rate). In the example, I see that the printk() strings get outputed to UART_0 console which is normal.

    The "AT, test" string is supposed to be sent through UART_2 in this example but I don't see it being displayed. I expected that I see this string output in my external debugger console connected with my UART_2 pins. 

    In any case, how would you test UART_2 in this case ? I feel a bit lost with this. Any help would be great :).

    Can I test the string output by connecting my UART_2 to any COM port ?

    Regards,

    Adeel.

  • Hi, Adeel!

    I routed the UART2 to VCOM2 for testing and got the output there (my .overlay file is setup thereafter). Could you try that first maybe? Note that the output then will arrive on a different COM port than the debug messages.

    In addition, P0.17 is used for board control on the nRF9160DK, as noted here. It should not be used for any other purpose.

    Your devicetree_unfixed.h seems correct, and you should not need to have the CONFIG_COMPILER_OPT in your prj.conf. You can use my prj.conf for reference. 

    Best regards,
    Carl Richard

Related