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

Related