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.

Parents
  • 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,

    Noted. I changed my pin numbers to (10,11,12,13). Thanks for that advice.

    Could you guide me a bit about routing UART_2 to VCOM_2. The documentation says VCOM_2 is not connected to 9160. 

    Also, my SPM file gives an error while building.

    The error says "Include expects Filename". Which filename is the error referring to ? 

    Regards,

    Adeel.

  • Hi Carl,

    Is it also required to do some modification in this setting ?

    I tried modifying the overlay file by adding the above settings that I found. Do I need to route the above lines to UART_2 ? 

    Regards,

    Adeel.

  • Hi again, Adeel!

    According to our documentation VCOM_2 is not connected to the nRF9160 by default, but in the sample I've attached here the UART2 is routed to VCOM_2 using overlay. As noted in the documentation VCOM_2 is connected to P0.01, P0.02, P0.15 and P0.14 of the nRF9160 GPIO. 

    With regards to the error, could you try to reload the project after editing the .overlay and prj.conf files? 

    It should be enough to edit the .overlay files as shown in the sample I attached.  

    Best regards,
    Carl Richard

  • Hi Carl,

    I tried to implement your project again with your settings. My overlay file is:

    nrf9160dk_nrf9160ns.overlay

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

    The settings are the same in SPM with nrf9160dk_nrf9160.overlay file. However, I don't see the desired output on my screen. 

    For trial, I tried to change my tx,rx,rts,cts pins to 10,11,12,13 respectively and then put a loopback between 10 and 11 (tx and rx) just to see if it is being transmitted. I see this output:

    I want to transmit this ""AT,test" through my Tx externally. I see that the loopback works. My connection to check the loopback is: 

    My connection to transmit to external is: 

    My external communication is to a ASCII string capture console and I have a TTL_485 converter in between. I am trying to use your project to try and send the strings out. When I remove the loopback and connect externally, I dont see the "AT,test" either on my PC console or my ASCII capture console. 

    What could I be doing wrong here ? Any leads would be appreciated :). Thanks for the time.

    Regards,

    Adeel.

  • Hello again!

    Good that the loopback works. Then the problem is not (directly) with the code at least.

    I guess the issue is then related to your wiring/module, but I'm not familiar with the module you are using (or RS485). However, could you try switching around your connections so that rx(P0.10) -> RO and tx(P0.11)->DO and see if that helps? 

    In addition, I believe and RE/DE are required to enable receive/transmit? Maybe you need to control that from the nRF9160 somehow. I found a case that did something similar to you, so you could have a look at that.

    This one is also relevant!

    Best regards,
    Carl Richard

Reply
  • Hello again!

    Good that the loopback works. Then the problem is not (directly) with the code at least.

    I guess the issue is then related to your wiring/module, but I'm not familiar with the module you are using (or RS485). However, could you try switching around your connections so that rx(P0.10) -> RO and tx(P0.11)->DO and see if that helps? 

    In addition, I believe and RE/DE are required to enable receive/transmit? Maybe you need to control that from the nRF9160 somehow. I found a case that did something similar to you, so you could have a look at that.

    This one is also relevant!

    Best regards,
    Carl Richard

Children
  • Hi Carl,

    Thanks for the lead. I think you are right, but for now I was just trying to transmit a string just to see if the communication works. So, I did not connect RE/DE right now. Can I just control the RE/DE through controlling the GPIO's and setting a 1/0 like this:

    gpio_pin_configure(gpio, 12, GPIO_OUTPUT);

    gpio_pin_set(gpio, 12, 1);

    printk("GPIO 12 Value is: %d\n", gpio_pin_get(gpio, 12));

    Is this the correct way to setup the GPIO pins ? If so, I will try to set it up for my RE/DE and configure it for my transmission. 

    Also, my SPM still gives me the error posted above. Do you think this can also be an issue here regarding external communication (or) is that independent of this ?

    Regards,

    Adeel.

  • Hi, Adeel!

    I see that you are getting help from Simon on the same matter in this ticket, so I'll close this one. 

    Please open another ticket if you encounter other issues.

    Best regards,
    Carl Richard

Related