Uart flow control for rs485 transmitter on the Odroid C4

Post Reply
Rens
Posts: 40
Joined: Wed Dec 01, 2021 6:27 pm
languages_spoken: english
ODROIDs: Odroid C4
Has thanked: 4 times
Been thanked: 0
Contact:

Uart flow control for rs485 transmitter on the Odroid C4

Post by Rens »

For a project i wanna communicate via RS485 from the Odroid C4. I already maneged to setup a uart connection in C with open, read and write, with a uart to USB cp2102. I also managed to to write via RS485 by just setting the flow control pin high. Sadly i cannot get the timing right to read the response which is being send immediately after the messaged is checked.

I read that the Odroid H1 and C1 can use the RTS and CTS from from uart. I also see those pin in the pinout on the odroid wiki, but i don't know how i can use them. I tried to configure them, but it did not work.

What would i need to do to use the RTS pin set the flow control pin high and low with reading and writing from and to via RS485/Uart?

User avatar
odroid
Site Admin
Posts: 38556
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English, Korean
ODROIDs: ODROID
Has thanked: 2219 times
Been thanked: 1298 times
Contact:

Re: Uart flow control for rs485 transmitter on the Odroid C4

Post by odroid »

Check GPIO numbers on the 40pin header first.
https://wiki.odroid.com/odroid-c4/hardw ... connectors

And, Check UART numbers.
https://wiki.odroid.com/odroid-c4/appli ... /gpio/uart

Then, Find the RTS/CTS signals pin-mux configuration from the SoC S905X3 datasheet.
https://wiki.odroid.com/odroid-c4/hardw ... _datasheet

Finally, you need to modify or generate a kernel device tree file to activate the RTS/CTS functionality if the signals exist on the 40pin header.

Rens
Posts: 40
Joined: Wed Dec 01, 2021 6:27 pm
languages_spoken: english
ODROIDs: Odroid C4
Has thanked: 4 times
Been thanked: 0
Contact:

Re: Uart flow control for rs485 transmitter on the Odroid C4

Post by Rens »

I found al that information already.
Uart_a: (aka uart0 or dev/ttyS1)
TX: pin 8 -> gpio 488 (GPIOX.12)
RX: pin 10 -> gpio 489 (GPIOX.13)
RTS: pin 29 -> gpio 490 (GPIOX.14)
CTS: pin 31 -> gpio 491 (GPIOX.15)

But i have no expierence on how to generate or modify dtbo or dts files or what the mux configuration should look like.
I still tried to make a small code snipped by looking at an example from another post:
viewtopic.php?t=37073

with a copy of the a_uart from:
https://github.com/hardkernel/linux/blo ... .dtsi#L369

Code: Select all

/dts-v1/;
/plugin/;

#include <dt-bindings/gpio/meson-g12a-gpio.h>
#include <dt-bindings/gpio/gpio.h>
/{
        fragment@0{
                __overlay__{
                        status = "okay"

                        a_uart_pins:a_uart{
                                amlogic,setmask=<4 0x3c00>;
                                amlogic,pins="GPIOX_12", "GPIOX_13", "GPIOX_14", "GPIOX_15";
                        };
                };
        };
};
but sadly i get the error:

Error: uartA.dts:4.1-9 syntax error
FATAL ERROR: Unable to parse input tree

lsc1117
Posts: 280
Joined: Thu Aug 22, 2013 12:46 am
languages_spoken: english
Location: South Korea
Has thanked: 9 times
Been thanked: 37 times
Contact:

Re: Uart flow control for rs485 transmitter on the Odroid C4

Post by lsc1117 »

Hello Rens,

Could you try this source?

Code: Select all

/dts-v1/;
/plugin/;

#include <dt-bindings/gpio/meson-g12a-gpio.h>
#include <dt-bindings/gpio/gpio.h>
/{
        fragment@0{
                target = <&uart_A>;
                __overlay__{
                        status = "okay";
                        pinctrl-names = "default";
                        pinctrl-0 = <&a_uart_pins>;

                        a_uart_pins:a_uart{
                                mux {
                                        groups = "uart_tx_a",
                                                "uart_rx_a",
                                                "uart_cts_a",
                                                "uart_rts_a";
                                        function = "uart_a";
                                };
                        };
                };
        };
};


Rens
Posts: 40
Joined: Wed Dec 01, 2021 6:27 pm
languages_spoken: english
ODROIDs: Odroid C4
Has thanked: 4 times
Been thanked: 0
Contact:

Re: Uart flow control for rs485 transmitter on the Odroid C4

Post by Rens »

lsc1117 wrote:
Tue Jan 11, 2022 6:54 pm
Hello Rens,

Could you try this source?

Code: Select all

/dts-v1/;
/plugin/;

#include <dt-bindings/gpio/meson-g12a-gpio.h>
#include <dt-bindings/gpio/gpio.h>
/{
        fragment@0{
                target = <&uart_A>;
                __overlay__{
                        status = "okay";
                        pinctrl-names = "default";
                        pinctrl-0 = <&a_uart_pins>;

                        a_uart_pins:a_uart{
                                mux {
                                        groups = "uart_tx_a",
                                                "uart_rx_a",
                                                "uart_cts_a",
                                                "uart_rts_a";
                                        function = "uart_a";
                                };
                        };
                };
        };
};

I still get the same result (I created a file called uartA.dts):
root@odroid:/media/boot/amlogic/overlays/odroidc4# dtc -I dts -O dtb -o uartA.dtbo uartA.dts
Error: uartA.dts:4.1-9 syntax error
FATAL ERROR: Unable to parse input tree

User avatar
tobetter
Posts: 8896
Joined: Mon Feb 25, 2013 10:55 am
languages_spoken: Korean, English
ODROIDs: Many
Location: Paju, South Korea
Has thanked: 521 times
Been thanked: 1421 times
Contact:

Re: Uart flow control for rs485 transmitter on the Odroid C4

Post by tobetter »

Rens wrote:
Tue Jan 11, 2022 7:34 pm
lsc1117 wrote:
Tue Jan 11, 2022 6:54 pm
Hello Rens,

Could you try this source?

Code: Select all

/dts-v1/;
/plugin/;

#include <dt-bindings/gpio/meson-g12a-gpio.h>
#include <dt-bindings/gpio/gpio.h>
/{
        fragment@0{
                target = <&uart_A>;
                __overlay__{
                        status = "okay";
                        pinctrl-names = "default";
                        pinctrl-0 = <&a_uart_pins>;

                        a_uart_pins:a_uart{
                                mux {
                                        groups = "uart_tx_a",
                                                "uart_rx_a",
                                                "uart_cts_a",
                                                "uart_rts_a";
                                        function = "uart_a";
                                };
                        };
                };
        };
};

I still get the same result (I created a file called uartA.dts):
root@odroid:/media/boot/amlogic/overlays/odroidc4# dtc -I dts -O dtb -o uartA.dtbo uartA.dts
Error: uartA.dts:4.1-9 syntax error
FATAL ERROR: Unable to parse input tree
You should try to build make dtbs at the top directory of Linux source tree, not in the overlay directory.

Rens
Posts: 40
Joined: Wed Dec 01, 2021 6:27 pm
languages_spoken: english
ODROIDs: Odroid C4
Has thanked: 4 times
Been thanked: 0
Contact:

Re: Uart flow control for rs485 transmitter on the Odroid C4

Post by Rens »

tobetter wrote:
Tue Jan 11, 2022 8:09 pm
Rens wrote:
Tue Jan 11, 2022 7:34 pm
lsc1117 wrote:
Tue Jan 11, 2022 6:54 pm
Hello Rens,

Could you try this source?

Code: Select all

/dts-v1/;
/plugin/;

#include <dt-bindings/gpio/meson-g12a-gpio.h>
#include <dt-bindings/gpio/gpio.h>
/{
        fragment@0{
                target = <&uart_A>;
                __overlay__{
                        status = "okay";
                        pinctrl-names = "default";
                        pinctrl-0 = <&a_uart_pins>;

                        a_uart_pins:a_uart{
                                mux {
                                        groups = "uart_tx_a",
                                                "uart_rx_a",
                                                "uart_cts_a",
                                                "uart_rts_a";
                                        function = "uart_a";
                                };
                        };
                };
        };
};

I still get the same result (I created a file called uartA.dts):
root@odroid:/media/boot/amlogic/overlays/odroidc4# dtc -I dts -O dtb -o uartA.dtbo uartA.dts
Error: uartA.dts:4.1-9 syntax error
FATAL ERROR: Unable to parse input tree
You should try to build make dtbs at the top directory of Linux source tree, not in the overlay directory.
I asume you mean in media/boot/amlogic directory?
I tested it there and also in the boot directory, but both fail to compile
Image
Attachments
compile fault.png
compile fault.png (16.98 KiB) Viewed 419 times

User avatar
tobetter
Posts: 8896
Joined: Mon Feb 25, 2013 10:55 am
languages_spoken: Korean, English
ODROIDs: Many
Location: Paju, South Korea
Has thanked: 521 times
Been thanked: 1421 times
Contact:

Re: Uart flow control for rs485 transmitter on the Odroid C4

Post by tobetter »

Rens wrote:
Tue Jan 11, 2022 8:20 pm
tobetter wrote:
Tue Jan 11, 2022 8:09 pm
Rens wrote:
Tue Jan 11, 2022 7:34 pm
lsc1117 wrote:
Tue Jan 11, 2022 6:54 pm
Hello Rens,

Could you try this source?

Code: Select all

/dts-v1/;
/plugin/;

#include <dt-bindings/gpio/meson-g12a-gpio.h>
#include <dt-bindings/gpio/gpio.h>
/{
        fragment@0{
                target = <&uart_A>;
                __overlay__{
                        status = "okay";
                        pinctrl-names = "default";
                        pinctrl-0 = <&a_uart_pins>;

                        a_uart_pins:a_uart{
                                mux {
                                        groups = "uart_tx_a",
                                                "uart_rx_a",
                                                "uart_cts_a",
                                                "uart_rts_a";
                                        function = "uart_a";
                                };
                        };
                };
        };
};

I still get the same result (I created a file called uartA.dts):
root@odroid:/media/boot/amlogic/overlays/odroidc4# dtc -I dts -O dtb -o uartA.dtbo uartA.dts
Error: uartA.dts:4.1-9 syntax error
FATAL ERROR: Unable to parse input tree
You should try to build make dtbs at the top directory of Linux source tree, not in the overlay directory.
I asume you mean in media/boot/amlogic directory?
I tested it there and also in the boot directory, but both fail to compile
Image
No, not in the device. Try with your PC after downloading Linux kernel source tree from Github.
https://wiki.odroid.com/odroid-c4/softw ... ing_kernel

Rens
Posts: 40
Joined: Wed Dec 01, 2021 6:27 pm
languages_spoken: english
ODROIDs: Odroid C4
Has thanked: 4 times
Been thanked: 0
Contact:

Re: Uart flow control for rs485 transmitter on the Odroid C4

Post by Rens »

tobetter wrote:
Tue Jan 11, 2022 8:24 pm
Rens wrote:
Tue Jan 11, 2022 8:20 pm
tobetter wrote:
Tue Jan 11, 2022 8:09 pm
Rens wrote:
Tue Jan 11, 2022 7:34 pm
lsc1117 wrote:
Tue Jan 11, 2022 6:54 pm
Hello Rens,

Could you try this source?

Code: Select all

/dts-v1/;
/plugin/;

#include <dt-bindings/gpio/meson-g12a-gpio.h>
#include <dt-bindings/gpio/gpio.h>
/{
        fragment@0{
                target = <&uart_A>;
                __overlay__{
                        status = "okay";
                        pinctrl-names = "default";
                        pinctrl-0 = <&a_uart_pins>;

                        a_uart_pins:a_uart{
                                mux {
                                        groups = "uart_tx_a",
                                                "uart_rx_a",
                                                "uart_cts_a",
                                                "uart_rts_a";
                                        function = "uart_a";
                                };
                        };
                };
        };
};

I still get the same result (I created a file called uartA.dts):
root@odroid:/media/boot/amlogic/overlays/odroidc4# dtc -I dts -O dtb -o uartA.dtbo uartA.dts
Error: uartA.dts:4.1-9 syntax error
FATAL ERROR: Unable to parse input tree
You should try to build make dtbs at the top directory of Linux source tree, not in the overlay directory.
I asume you mean in media/boot/amlogic directory?
I tested it there and also in the boot directory, but both fail to compile
Image
No, not in the device. Try with your PC after downloading Linux kernel source tree from Github.
https://wiki.odroid.com/odroid-c4/softw ... ing_kernel
I think i found it. I was in the wrong directory.
Image
Attachments
make_dtbs.png
make_dtbs.png (26.1 KiB) Viewed 415 times

Rens
Posts: 40
Joined: Wed Dec 01, 2021 6:27 pm
languages_spoken: english
ODROIDs: Odroid C4
Has thanked: 4 times
Been thanked: 0
Contact:

Re: Uart flow control for rs485 transmitter on the Odroid C4

Post by Rens »

Is compiling my own linux version the only way to get the RTS and CTS pins to work with open, read and write? or is there an easier way to customize the uart0.dtbo?

lsc1117
Posts: 280
Joined: Thu Aug 22, 2013 12:46 am
languages_spoken: english
Location: South Korea
Has thanked: 9 times
Been thanked: 37 times
Contact:

Re: Uart flow control for rs485 transmitter on the Odroid C4

Post by lsc1117 »

@Rens,

https://dn.odroid.com/source_peripheral ... s_cts.dtbo

copy this dtbo file into "amlogic/overlays/odroidc4/" on your boot partition.
And then, add "uart0_rts_cts" in your config.ini file on your boot partition.

Example,

Code: Select all

; Device Tree Overlay
overlay_resize=16384
overlay_profile=
overlays="uart0_rts_cts"

[overlay_custom]
overlays="i2c0 i2c1"

[overlay_hktft32]
overlays="hktft32"

[overlay_hktft35]
overlays="hktft35"

Rens
Posts: 40
Joined: Wed Dec 01, 2021 6:27 pm
languages_spoken: english
ODROIDs: Odroid C4
Has thanked: 4 times
Been thanked: 0
Contact:

Re: Uart flow control for rs485 transmitter on the Odroid C4

Post by Rens »

@lsc1117 I tried it out with the .dtbo file. But nothing was being send at all, even via uart0. When i converted it back to use uart0.dtbo, then it could send again via ttyS1.

lsc1117
Posts: 280
Joined: Thu Aug 22, 2013 12:46 am
languages_spoken: english
Location: South Korea
Has thanked: 9 times
Been thanked: 37 times
Contact:

Re: Uart flow control for rs485 transmitter on the Odroid C4

Post by lsc1117 »

@Rens,

I see. I'll make a new DTBO that works well in several hours.
These users thanked the author lsc1117 for the post:
Rens (Wed Jan 12, 2022 5:03 pm)

lsc1117
Posts: 280
Joined: Thu Aug 22, 2013 12:46 am
languages_spoken: english
Location: South Korea
Has thanked: 9 times
Been thanked: 37 times
Contact:

Re: Uart flow control for rs485 transmitter on the Odroid C4

Post by lsc1117 »

@Rens,

Please try again the new DTBO file. I have updated the "uart0_rts_cts.dtbo".
https://dn.odroid.com/source_peripheral ... s_cts.dtbo
And you can see the changed dts file as well.
https://dn.odroid.com/source_peripheral ... ts_cts.dts

You will see that the PIN mode has changed to ALT1 of PIN29 and PIN31 via wiringpi.
ALT1 means the UART function.

Code: Select all

odroid@odroid:~$ sudo gpio readall
 +-----+-----+---------+------+---+--- C4 ---+---+------+---------+-----+-----+
 | I/O | wPi |   Name  | Mode | V | Physical | V | Mode |  Name   | wPi | I/O |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 |     |     |    3.3V |      |   |  1 || 2  |   |      | 5V      |     |     |
 | 493 |   8 |   SDA.2 |   IN | 1 |  3 || 4  |   |      | 5V      |     |     |
 | 494 |   9 |   SCL.2 |   IN | 1 |  5 || 6  |   |      | 0V      |     |     |
 | 481 |   7 |  IO.481 |   IN | 1 |  7 || 8  | 1 | ALT1 | TxD1    | 15  | 488 |
 |     |     |      0V |      |   |  9 || 10 | 1 | ALT1 | RxD1    | 16  | 489 |
 | 479 |   0 |  IO.479 |   IN | 1 | 11 || 12 | 1 | IN   | IO.492  | 1   | 492 |
 | 480 |   2 |  IO.480 |   IN | 1 | 13 || 14 |   |      | 0V      |     |     |
 | 483 |   3 |  IO.483 |   IN | 1 | 15 || 16 | 1 | IN   | IO.476  | 4   | 476 |
 |     |     |    3.3V |      |   | 17 || 18 | 1 | IN   | IO.477  | 5   | 477 |
 | 484 |  12 |    MOSI |   IN | 1 | 19 || 20 |   |      | 0V      |     |     |
 | 485 |  13 |    MISO |   IN | 1 | 21 || 22 | 1 | IN   | IO.478  | 6   | 478 |
 | 487 |  14 |    SLCK |   IN | 1 | 23 || 24 | 1 | IN   | SS      | 10  | 486 |
 |     |     |      0V |      |   | 25 || 26 | 0 | IN   | IO. 23  | 11  | 433 |
 | 474 |  30 |   SDA.3 |   IN | 1 | 27 || 28 | 1 | IN   | SCL.3   | 31  | 475 |
 | 490 |  21 |  IO.490 | ALT1 | 1 | 29 || 30 |   |      | 0V      |     |     |
 | 491 |  22 |  IO.491 | ALT1 | 1 | 31 || 32 | 0 | IN   | IO. 24  | 26  | 434 |
 | 482 |  23 |  IO.482 |   IN | 0 | 33 || 34 |   |      | 0V      |     |     |
 | 495 |  24 |  IO.495 |   IN | 0 | 35 || 36 | 1 | OUT  | IO. 22  | 27  | 432 |
 |     |  25 |   AIN.2 |      |   | 37 || 38 |   |      | 1V8     | 28  |     |
 |     |     |      0V |      |   | 39 || 40 |   |      | AIN.0   | 29  |     |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 | I/O | wPi |   Name  | Mode | V | Physical | V | Mode |  Name   | wPi | I/O |
 +-----+-----+---------+------+---+--- C4 ---+---+------+---------+-----+-----+
odroid@odroid:~$
You can install the wiringpi with the following instructions on your C4.

Code: Select all

odroid@odroid:~$ sudo apt install software-properties-common
odroid@odroid:~$ sudo add-apt-repository ppa:hardkernel/ppa
odroid@odroid:~$ sudo apt update
odroid@odroid:~$ sudo apt install odroid-wiringpi

Rens
Posts: 40
Joined: Wed Dec 01, 2021 6:27 pm
languages_spoken: english
ODROIDs: Odroid C4
Has thanked: 4 times
Been thanked: 0
Contact:

Re: Uart flow control for rs485 transmitter on the Odroid C4

Post by Rens »

Not sure but for me it does not configure at all. I even created a new ubuntu 20.04 minimal version. Only vim, build-essential and git where install other the the programs you said to install.

(gpio readall -a output with uart0_rts_cts.dtbo)

Code: Select all

root@odroid:~# gpio readall -a
 +------+-----+----------+------+---+----+---- Model  ODROID-C4 ----+----+---+------+----------+-----+------+
 | GPIO | wPi |   Name   | Mode | V | DS | PU/PD | Physical | PU/PD | DS | V | Mode |   Name   | wPi | GPIO |
 +------+-----+----------+------+---+----+-------+----++----+-------+----+---+------+----------+-----+------+
 |      |     |     3.3V |      |   |    |       |  1 || 2  |       |    |   |      | 5V       |     |      |
 |  493 |   8 |    SDA.2 |   IN | 1 |  0 |   P/D |  3 || 4  |       |    |   |      | 5V       |     |      |
 |  494 |   9 |    SCL.2 |   IN | 1 |  0 |   P/U |  5 || 6  |       |    |   |      | GND(0V)  |     |      |
 |  481 |   7 | GPIO.481 |   IN | 1 |  0 |   P/U |  7 || 8  | P/U   | 0  | 1 | IN   | TxD1     | 15  | 488  |
 |      |     |  GND(0V) |      |   |    |       |  9 || 10 | P/U   | 0  | 1 | IN   | RxD1     | 16  | 489  |
 |  479 |   0 | GPIO.479 |   IN | 1 |  0 |   P/U | 11 || 12 | P/U   | 0  | 1 | IN   | GPIO.492 | 1   | 492  |
 |  480 |   2 | GPIO.480 |   IN | 1 |  0 |   P/U | 13 || 14 |       |    |   |      | GND(0V)  |     |      |
 |  483 |   3 | GPIO.483 |   IN | 1 |  0 |   P/U | 15 || 16 | P/U   | 0  | 1 | IN   | GPIO.476 | 4   | 476  |
 |      |     |     3.3V |      |   |    |       | 17 || 18 | P/U   | 0  | 1 | IN   | GPIO.477 | 5   | 477  |
 |  484 |  12 |     MOSI |   IN | 1 |  0 |   P/U | 19 || 20 |       |    |   |      | GND(0V)  |     |      |
 |  485 |  13 |     MISO |   IN | 1 |  0 |   P/U | 21 || 22 | P/U   | 0  | 1 | IN   | GPIO.478 | 6   | 478  |
 |  487 |  14 |     SLCK |   IN | 1 |  0 |   P/U | 23 || 24 | P/U   | 0  | 1 | IN   | SS       | 10  | 486  |
 |      |     |  GND(0V) |      |   |    |       | 25 || 26 | P/D   | 0  | 0 | IN   | GPIO. 23 | 11  | 433  |
 |  474 |  30 |    SDA.3 |   IN | 1 |  0 |   P/U | 27 || 28 | P/U   | 0  | 1 | IN   | SCL.3    | 31  | 475  |
 |  490 |  21 | GPIO.490 |   IN | 1 |  0 |   P/U | 29 || 30 |       |    |   |      | GND(0V)  |     |      |
 |  491 |  22 | GPIO.491 |   IN | 0 |  0 |   P/U | 31 || 32 | P/D   | 0  | 0 | IN   | GPIO. 24 | 26  | 434  |
 |  482 |  23 | GPIO.482 |   IN | 0 |  0 |   P/D | 33 || 34 |       |    |   |      | GND(0V)  |     |      |
 |  495 |  24 | GPIO.495 |   IN | 0 |  0 | DSBLD | 35 || 36 | P/D   | 0  | 1 | OUT  | GPIO. 22 | 27  | 432  |
 |      |  25 |    AIN.2 |      |   |    |       | 37 || 38 |       |    |   |      | 1V8      | 28  |      |
 |      |     |  GND(0V) |      |   |    |       | 39 || 40 |       |    |   |      | AIN.0    | 29  |      |
 +------+-----+----------+------+---+----+-------+----++----+-------+----+---+------+----------+-----+------+
 | GPIO | wPi |   Name   | Mode | V | DS | PU/PD | Physical | PU/PD | DS | V | Mode |   Name   | wPi | GPIO |
 +------+-----+----------+------+---+----+---- Model  ODROID-C4 ----+----+---+------+----------+-----+------+
(gpio readall -a output with uart0.dtbo)

Code: Select all

root@odroid:~# gpio readall -a
 +------+-----+----------+------+---+----+---- Model  ODROID-C4 ----+----+---+------+----------+-----+------+
 | GPIO | wPi |   Name   | Mode | V | DS | PU/PD | Physical | PU/PD | DS | V | Mode |   Name   | wPi | GPIO |
 +------+-----+----------+------+---+----+-------+----++----+-------+----+---+------+----------+-----+------+
 |      |     |     3.3V |      |   |    |       |  1 || 2  |       |    |   |      | 5V       |     |      |
 |  493 |   8 |    SDA.2 |   IN | 1 |  0 |   P/D |  3 || 4  |       |    |   |      | 5V       |     |      |
 |  494 |   9 |    SCL.2 |   IN | 1 |  0 |   P/U |  5 || 6  |       |    |   |      | GND(0V)  |     |      |
 |  481 |   7 | GPIO.481 |   IN | 1 |  0 |   P/U |  7 || 8  | P/U   | 0  | 1 | ALT1 | TxD1     | 15  | 488  |
 |      |     |  GND(0V) |      |   |    |       |  9 || 10 | P/U   | 0  | 1 | ALT1 | RxD1     | 16  | 489  |
 |  479 |   0 | GPIO.479 |   IN | 1 |  0 |   P/U | 11 || 12 | P/U   | 0  | 1 | IN   | GPIO.492 | 1   | 492  |
 |  480 |   2 | GPIO.480 |   IN | 1 |  0 |   P/U | 13 || 14 |       |    |   |      | GND(0V)  |     |      |
 |  483 |   3 | GPIO.483 |   IN | 1 |  0 |   P/U | 15 || 16 | P/U   | 0  | 1 | IN   | GPIO.476 | 4   | 476  |
 |      |     |     3.3V |      |   |    |       | 17 || 18 | P/U   | 0  | 1 | IN   | GPIO.477 | 5   | 477  |
 |  484 |  12 |     MOSI |   IN | 1 |  0 |   P/U | 19 || 20 |       |    |   |      | GND(0V)  |     |      |
 |  485 |  13 |     MISO |   IN | 1 |  0 |   P/U | 21 || 22 | P/U   | 0  | 1 | IN   | GPIO.478 | 6   | 478  |
 |  487 |  14 |     SLCK |   IN | 1 |  0 |   P/U | 23 || 24 | P/U   | 0  | 1 | IN   | SS       | 10  | 486  |
 |      |     |  GND(0V) |      |   |    |       | 25 || 26 | P/D   | 0  | 0 | IN   | GPIO. 23 | 11  | 433  |
 |  474 |  30 |    SDA.3 |   IN | 1 |  0 |   P/U | 27 || 28 | P/U   | 0  | 1 | IN   | SCL.3    | 31  | 475  |
 |  490 |  21 | GPIO.490 |   IN | 1 |  0 |   P/U | 29 || 30 |       |    |   |      | GND(0V)  |     |      |
 |  491 |  22 | GPIO.491 |   IN | 0 |  0 |   P/U | 31 || 32 | P/D   | 0  | 0 | IN   | GPIO. 24 | 26  | 434  |
 |  482 |  23 | GPIO.482 |   IN | 0 |  0 |   P/D | 33 || 34 |       |    |   |      | GND(0V)  |     |      |
 |  495 |  24 | GPIO.495 |   IN | 0 |  0 | DSBLD | 35 || 36 | P/D   | 0  | 1 | OUT  | GPIO. 22 | 27  | 432  |
 |      |  25 |    AIN.2 |      |   |    |       | 37 || 38 |       |    |   |      | 1V8      | 28  |      |
 |      |     |  GND(0V) |      |   |    |       | 39 || 40 |       |    |   |      | AIN.0    | 29  |      |
 +------+-----+----------+------+---+----+-------+----++----+-------+----+---+------+----------+-----+------+
 | GPIO | wPi |   Name   | Mode | V | DS | PU/PD | Physical | PU/PD | DS | V | Mode |   Name   | wPi | GPIO |
 +------+-----+----------+------+---+----+---- Model  ODROID-C4 ----+----+---+------+----------+-----+------+
[Edit]
I still had the old Uart0_rts_cts file. I have the correct modes now

Rens
Posts: 40
Joined: Wed Dec 01, 2021 6:27 pm
languages_spoken: english
ODROIDs: Odroid C4
Has thanked: 4 times
Been thanked: 0
Contact:

Re: Uart flow control for rs485 transmitter on the Odroid C4

Post by Rens »

The RTS pin for Uart works now indeed, but the new problem is that it keeps the pin low the whole time (while writing and reading). I was expecting that it would set the pin back high again if it was reading.

I currently have the Uart connected to my pc with a cp2102 uart to usb and the RTS pin connected to a led and oscilloscope.

I am using the open, write, read and close for uart and termios to configure it all.

Code: Select all

    // ** Uart connection setup **
    // Create instance of termios to configure uart
    struct termios tty;

    // Open an connection
    fd = open(Path, O_RDWR);

    // Check for errors
    if (fd < 0) 
            printf("Error %i from open: %s\n", errno, strerror(errno));

    if(tcgetattr(fd, &tty) != 0) 
            printf("Error %i from tcgetattr: %s\n", errno, strerror(errno));

    // Set control flags
    tty.c_cflag &= ~PARENB;     // Clear parity bit, disabling parity (most common)
    tty.c_cflag &= ~CSTOPB;     // Clear stop field, only one stop bit used in communication (most common)
    tty.c_cflag &= ~CSIZE;      // Clear all bits that set the data size 
    tty.c_cflag |= CS8;         // 8 bits per byte (most common)
    tty.c_cflag &= ~CRTSCTS;    // Disable RTS/CTS hardware flow control (most common)
    tty.c_cflag |= B9600 |CREAD | CLOCAL; // Turn on READ & ignore ctrl lines (CLOCAL = 1)

    // Set local mode flags
    tty.c_lflag &= ~ICANON;
    tty.c_lflag &= ~ECHO;       // Disable echo
    tty.c_lflag &= ~ECHOE;      // Disable erasure
    tty.c_lflag &= ~ECHONL;     // Disable new-line echo
    tty.c_lflag &= ~ISIG;       // Disable interpretation of INTR, QUIT and SUSP

    // Set input flags
    tty.c_iflag &= ~(IXON | IXOFF | IXANY); // Turn off s/w flow ctrl
    tty.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL); // Disable any special handling of received bytes


    tty.c_cc[VTIME] = 0;
    tty.c_cc[VMIN] = 1;

    if (tcsetattr(fd, TCSANOW, &tty) != 0) 
	    printf("Error %i from tcsetattr: %s\n", errno, strerror(errno));
    int status = write(fd, tmpSendingMsg, sizeof(tmpSendingMsg)+1); 

    if(0 < status)
    {
        read(fd, tmpreturn, 4);
        printf("Read = %s \n", tmpreturn)
   }
   
   close(fd)

Rens
Posts: 40
Joined: Wed Dec 01, 2021 6:27 pm
languages_spoken: english
ODROIDs: Odroid C4
Has thanked: 4 times
Been thanked: 0
Contact:

Re: Uart flow control for rs485 transmitter on the Odroid C4

Post by Rens »

@lsc1117 does the Uart A rts pin change state when it send and receives data via uart?

lsc1117
Posts: 280
Joined: Thu Aug 22, 2013 12:46 am
languages_spoken: english
Location: South Korea
Has thanked: 9 times
Been thanked: 37 times
Contact:

Re: Uart flow control for rs485 transmitter on the Odroid C4

Post by lsc1117 »

@Rens,

The RTS pin should be kept low if the receive buffers of the UART have enough, otherwise, it should be kept high.
Try to set your UART's baudrate down and then send a large amount of data.
I'll also test the UART hardware flow control.

Rens
Posts: 40
Joined: Wed Dec 01, 2021 6:27 pm
languages_spoken: english
ODROIDs: Odroid C4
Has thanked: 4 times
Been thanked: 0
Contact:

Re: Uart flow control for rs485 transmitter on the Odroid C4

Post by Rens »

lsc1117 wrote:
Thu Jan 13, 2022 11:25 pm
@Rens,

The RTS pin should be kept low if the receive buffers of the UART have enough, otherwise, it should be kept high.
Try to set your UART's baudrate down and then send a large amount of data.
I'll also test the UART hardware flow control.
That is what i would expect it to do, but in my test setup it stays low the whole time.
I made a test setup using the Odroid and a CP2102 where the RTS pin is only connected to a LED. As soon as i call the open( "/dev/ttyS1", O_RDWR) the light turns off (not reading or writing to it) until i close the connection.

This alle happens all before i setup the Uart baudrate to 9600.

[Edit]

I tried testing diverent types of flags in the open() (O_WR, O_RD and O_RDWR | O_NOCTTY) but all had the same result: flow control pin RTS stays low the whole time the file descriptor is open.
Last edited by Rens on Fri Jan 14, 2022 6:06 pm, edited 1 time in total.

lsc1117
Posts: 280
Joined: Thu Aug 22, 2013 12:46 am
languages_spoken: english
Location: South Korea
Has thanked: 9 times
Been thanked: 37 times
Contact:

Re: Uart flow control for rs485 transmitter on the Odroid C4

Post by lsc1117 »

@Rens,

I have tested an UART hardware flow control on my C4.
The RTS pin should be kept high in an idle state because the pin is active high.
So, my C4's RTS pin is keeping high in idle.
But when I send a large amount of data like this, the pin changes to LOW.

Code: Select all

root@odroid:~# stty -F /dev/ttyS1 4800
root@odroid:~# cat /dev/random > /dev/ttyS1


lsc1117
Posts: 280
Joined: Thu Aug 22, 2013 12:46 am
languages_spoken: english
Location: South Korea
Has thanked: 9 times
Been thanked: 37 times
Contact:

Re: Uart flow control for rs485 transmitter on the Odroid C4

Post by lsc1117 »

@Rens,

I have tested with my two ODROID-C4, one is as an UART master and the other one is as an UART slave.
I have set both the baud rate to 4800.

Rens
Posts: 40
Joined: Wed Dec 01, 2021 6:27 pm
languages_spoken: english
ODROIDs: Odroid C4
Has thanked: 4 times
Been thanked: 0
Contact:

Re: Uart flow control for rs485 transmitter on the Odroid C4

Post by Rens »

lsc1117 wrote:
Fri Jan 14, 2022 6:01 pm
@Rens,

I have tested with my two ODROID-C4, one is as an UART master and the other one is as an UART slave.
I have set both the baud rate to 4800.
How did you setup the slave? i might be able to test the same setup with the odroid C4 and cp2102.

Running it from a C program with the open, read and write functions only keeps the rts pin high.

Rens
Posts: 40
Joined: Wed Dec 01, 2021 6:27 pm
languages_spoken: english
ODROIDs: Odroid C4
Has thanked: 4 times
Been thanked: 0
Contact:

Re: Uart flow control for rs485 transmitter on the Odroid C4

Post by Rens »

Rens wrote:
Fri Jan 14, 2022 5:52 pm
lsc1117 wrote:
Thu Jan 13, 2022 11:25 pm
@Rens,

The RTS pin should be kept low if the receive buffers of the UART have enough, otherwise, it should be kept high.
Try to set your UART's baudrate down and then send a large amount of data.
I'll also test the UART hardware flow control.
That is what i would expect it to do, but in my test setup it stays low the whole time.
I made a test setup using the Odroid and a CP2102 where the RTS pin is only connected to a LED. As soon as i call the open( "/dev/ttyS1", O_RDWR) the light turns off (not reading or writing to it) until i close the connection.

This alle happens all before i setup the Uart baudrate to 9600.

[Edit]

I tried testing diverent types of flags in the open() (O_WR, O_RD and O_RDWR | O_NOCTTY) but all had the same result: flow control pin RTS stays low the whole time the file descriptor is open.
With my C program is only keeps the RTS pin high the whole time

[Edit]
I tested the odroid as a reader with $ minicom -b 9600 -D /dev/ttyS1 and the rts pin stays low the while time

lsc1117
Posts: 280
Joined: Thu Aug 22, 2013 12:46 am
languages_spoken: english
Location: South Korea
Has thanked: 9 times
Been thanked: 37 times
Contact:

Re: Uart flow control for rs485 transmitter on the Odroid C4

Post by lsc1117 »

@Rens,

First of all, I enabled UART RTS and CTS with the DTBO on both master and slave.
And then, I set the baud rate of them to 4800 to make a bottleneck easier with the following command.

Master, Slave

Code: Select all

stty -F /dev/ttyS1 4800
Master C4

Code: Select all

cat /dev/random > /dev/ttyS1
Slave C4

Code: Select all

cat /dev/ttyS1

Rens
Posts: 40
Joined: Wed Dec 01, 2021 6:27 pm
languages_spoken: english
ODROIDs: Odroid C4
Has thanked: 4 times
Been thanked: 0
Contact:

Re: Uart flow control for rs485 transmitter on the Odroid C4

Post by Rens »

lsc1117 wrote:
Fri Jan 14, 2022 6:44 pm
@Rens,

First of all, I enabled UART RTS and CTS with the DTBO on both master and slave.
And then, I set the baud rate of them to 4800 to make a bottleneck easier with the following command.

Master, Slave

Code: Select all

stty -F /dev/ttyS1 4800
Master C4

Code: Select all

cat /dev/random > /dev/ttyS1
Slave C4

Code: Select all

cat /dev/ttyS1
I have tried it on my C4 to with setting
stty -F /dev/ttyS1 4800

the using slave C4 (connecting the CTS pin nonstop to the 3.3V)
cat /dev/ttyS1

But my RTS pin goes low the moment i execute the slave C4 command.
everything i type in the putty terminal of my CP2102 apears normaly in de odroid terminal

Rens
Posts: 40
Joined: Wed Dec 01, 2021 6:27 pm
languages_spoken: english
ODROIDs: Odroid C4
Has thanked: 4 times
Been thanked: 0
Contact:

Re: Uart flow control for rs485 transmitter on the Odroid C4

Post by Rens »

@lsc1117 do you enable the Uart RTS and CTS pins in the terminal before setting the baudrate or are they automaticly set when you add them to the config.ini?
I have deleted the uart0.dtbo file and replaced it with the uart0_rts_cts.dtbo file that is also added to the overlays in config.ini

lsc1117
Posts: 280
Joined: Thu Aug 22, 2013 12:46 am
languages_spoken: english
Location: South Korea
Has thanked: 9 times
Been thanked: 37 times
Contact:

Re: Uart flow control for rs485 transmitter on the Odroid C4

Post by lsc1117 »

@Rens,

Yes, the hardware flow control is enabled by default. You can check this "sudo stty -a -F /dev/ttyS1" command.
You will find "crtscts" setting in the results.

Rens
Posts: 40
Joined: Wed Dec 01, 2021 6:27 pm
languages_spoken: english
ODROIDs: Odroid C4
Has thanked: 4 times
Been thanked: 0
Contact:

Re: Uart flow control for rs485 transmitter on the Odroid C4

Post by Rens »

lsc1117 wrote:
Fri Jan 14, 2022 9:35 pm
@Rens,

Yes, the hardware flow control is enabled by default. You can check this "sudo stty -a -F /dev/ttyS1" command.
You will find "crtscts" setting in the results.
What could be a reason that the flow control pin RTS only changes state when open() en close() are called and not with the write() and read().
This is my output.

Code: Select all

root@odroid:/# stty -a -F /dev/ttyS1
speed 9600 baud; rows 0; columns 0; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; discard = ^O; min = 9; time = 0;
-parenb -parodd -cmspar cs8 hupcl -cstopb cread clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl -ixon -ixoff -iuclc -ixany -imaxbel -iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
-isig -icanon iexten -echo -echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke -flusho -extproc

Rens
Posts: 40
Joined: Wed Dec 01, 2021 6:27 pm
languages_spoken: english
ODROIDs: Odroid C4
Has thanked: 4 times
Been thanked: 0
Contact:

Re: Uart flow control for rs485 transmitter on the Odroid C4

Post by Rens »

@lsc1117
Can you connect your RTS pin to an LED to see it's behavior both as a Master and a Slave. I wonder if the RTS pin state is different on your boards.

lsc1117
Posts: 280
Joined: Thu Aug 22, 2013 12:46 am
languages_spoken: english
Location: South Korea
Has thanked: 9 times
Been thanked: 37 times
Contact:

Re: Uart flow control for rs485 transmitter on the Odroid C4

Post by lsc1117 »

@Rens,

Sorry for the late response.

I have made a video you can show the RTS behavior with LED.
https://dn.odroid.com/source_peripheral ... %20iOS.MOV

The left LCD shows the results of "screen /dev/ttyS1" as UART slave.
And the right LCD is the UART master sending data to the slave.

When the master(right C4) send data to the slave(left C4) with "cat /dev/random > /dev/ttyS1", the yellow LED turns off because the receive buffer busy.
When the master stops sending data to the slave, the yellow LED turns on.
These users thanked the author lsc1117 for the post:
Rens (Mon Jan 17, 2022 6:21 pm)

lsc1117
Posts: 280
Joined: Thu Aug 22, 2013 12:46 am
languages_spoken: english
Location: South Korea
Has thanked: 9 times
Been thanked: 37 times
Contact:

Re: Uart flow control for rs485 transmitter on the Odroid C4

Post by lsc1117 »

@Rens,

When nothing is connected to the RTS pin on master, the pin should be high by default.

Rens
Posts: 40
Joined: Wed Dec 01, 2021 6:27 pm
languages_spoken: english
ODROIDs: Odroid C4
Has thanked: 4 times
Been thanked: 0
Contact:

Re: Uart flow control for rs485 transmitter on the Odroid C4

Post by Rens »

@lsc1117

Thank you a lot for making the video. I am guessing that the green led is the RTS pin from the slave odroid, which is also turned off? Even tho the uart buss is not sending any data.

Could it be that the RTS pin is low when a connection to the /dev/ttyS1 device? This would explain the behavior I see when I open() and close() the connection (RTS pin toggles) and not with write() and read() (no toggle happens).

Is there a way to customize this behavior?

[Note:]
I am using uart with the open(), write(), read() and open() calls from the linux posix. I also tried to switch the gpio manually, but i needed to wait a full second to send data before i can switch the flow control pin state to read a response.

lsc1117
Posts: 280
Joined: Thu Aug 22, 2013 12:46 am
languages_spoken: english
Location: South Korea
Has thanked: 9 times
Been thanked: 37 times
Contact:

Re: Uart flow control for rs485 transmitter on the Odroid C4

Post by lsc1117 »

@Rens,

The green LED is also turned on but not bright.

Could you try this dtbo?

https://dn.odroid.com/source_peripheral ... trong.dtbo

This dtbo has been added pull-up and drive-strength higher.

You can check the pull-up and drive-strength properties in this dts file.
https://dn.odroid.com/source_peripheral ... strong.dts

Rens
Posts: 40
Joined: Wed Dec 01, 2021 6:27 pm
languages_spoken: english
ODROIDs: Odroid C4
Has thanked: 4 times
Been thanked: 0
Contact:

Re: Uart flow control for rs485 transmitter on the Odroid C4

Post by Rens »

@lsc1117
My odroid turn the RTS pin off with both cat /dev/ttyS1 and cat /dev/random > /dev/ttyS1.
That is not an issue while executing the slave command, but it does the same if it is the master. Also it prints nothing, even if i hardwire the cts pin to 3V3 or ground.
no uart received.png
no uart received.png (118.55 KiB) Viewed 167 times

lsc1117
Posts: 280
Joined: Thu Aug 22, 2013 12:46 am
languages_spoken: english
Location: South Korea
Has thanked: 9 times
Been thanked: 37 times
Contact:

Re: Uart flow control for rs485 transmitter on the Odroid C4

Post by lsc1117 »

@Rens,

If you don't connect anything to the RTS/CTS pin, is the RTS pin set as HIGH?

Rens
Posts: 40
Joined: Wed Dec 01, 2021 6:27 pm
languages_spoken: english
ODROIDs: Odroid C4
Has thanked: 4 times
Been thanked: 0
Contact:

Re: Uart flow control for rs485 transmitter on the Odroid C4

Post by Rens »

@lsc1117
yeah when i dont run anything, so no command like cat /dev/ttyS1 or cat /dev/random > /dev/ttyS1 (running idle) then the pin is high.
Idle state, no commands executed in this state
Idle state, no commands executed in this state
idleState.jpeg (158.32 KiB) Viewed 157 times

lsc1117
Posts: 280
Joined: Thu Aug 22, 2013 12:46 am
languages_spoken: english
Location: South Korea
Has thanked: 9 times
Been thanked: 37 times
Contact:

Re: Uart flow control for rs485 transmitter on the Odroid C4

Post by lsc1117 »

@Rens,

According to the CP2102 datasheet, the RTS and CTS pins are active low. And The C4 has active high pins for RTS and CTS.

Rens
Posts: 40
Joined: Wed Dec 01, 2021 6:27 pm
languages_spoken: english
ODROIDs: Odroid C4
Has thanked: 4 times
Been thanked: 0
Contact:

Re: Uart flow control for rs485 transmitter on the Odroid C4

Post by Rens »

Rens wrote:
Tue Jan 18, 2022 4:32 pm
@lsc1117
My odroid turn the RTS pin off with both cat /dev/ttyS1 and cat /dev/random > /dev/ttyS1.
That is not an issue while executing the slave command, but it does the same if it is the master. Also it prints nothing, even if i hardwire the cts pin to 3V3 or ground.

no uart received.png
@lsc1117
This setup exist of 3 devices: odroid C4, CP2102 that can only listen in on the rx pin and a microchip device. the microchip devices can send a message over RS485 just fine, but the odroid side has troubles controlling the flow control pin of the RS485 transmitter (low for reading and high for writing). When i execute cat /dev/ttyS1 the odroid should be able to read and the RTS pin for flow control is low, but i cannot see any messages is send.
while listening in on the RX line with the CP2102 i can see all messages come by (so that works and they get through the transmitter), but i don't see on the Odroid.

Hopefully this gives some more context of what i am trying to do.

User avatar
tobetter
Posts: 8896
Joined: Mon Feb 25, 2013 10:55 am
languages_spoken: Korean, English
ODROIDs: Many
Location: Paju, South Korea
Has thanked: 521 times
Been thanked: 1421 times
Contact:

Re: Uart flow control for rs485 transmitter on the Odroid C4

Post by tobetter »

Rens wrote:
Tue Jan 18, 2022 7:06 pm
Rens wrote:
Tue Jan 18, 2022 4:32 pm
@lsc1117
My odroid turn the RTS pin off with both cat /dev/ttyS1 and cat /dev/random > /dev/ttyS1.
That is not an issue while executing the slave command, but it does the same if it is the master. Also it prints nothing, even if i hardwire the cts pin to 3V3 or ground.

no uart received.png
@lsc1117
This setup exist of 3 devices: odroid C4, CP2102 that can only listen in on the rx pin and a microchip device. the microchip devices can send a message over RS485 just fine, but the odroid side has troubles controlling the flow control pin of the RS485 transmitter (low for reading and high for writing). When i execute cat /dev/ttyS1 the odroid should be able to read and the RTS pin for flow control is low, but i cannot see any messages is send.
while listening in on the RX line with the CP2102 i can see all messages come by (so that works and they get through the transmitter), but i don't see on the Odroid.

Hopefully this gives some more context of what i am trying to do.
I wonder if CTS pin on ODROID-C4 is low when 'Microchip device' which must be a CPU send a message.

Rens
Posts: 40
Joined: Wed Dec 01, 2021 6:27 pm
languages_spoken: english
ODROIDs: Odroid C4
Has thanked: 4 times
Been thanked: 0
Contact:

Re: Uart flow control for rs485 transmitter on the Odroid C4

Post by Rens »

@tobetter
How do you mean? The microchip device is a microcontroller that is able to send a message over the RS485 interface. i am only able to set it with a wire high or low.

[Note:]
This setup works fine with reading and writing via uart over the RX and TX pin connected between the CP2102 and the Odroid C4.

The RTS and CTS pins are not used then, i am only trying to use the RTS pin as a flow controller for the RS485 transmitter flow control pin. Toggling this manually by hand does not work fast enough, because i am trying to send a response on the message.

User avatar
tobetter
Posts: 8896
Joined: Mon Feb 25, 2013 10:55 am
languages_spoken: Korean, English
ODROIDs: Many
Location: Paju, South Korea
Has thanked: 521 times
Been thanked: 1421 times
Contact:

Re: Uart flow control for rs485 transmitter on the Odroid C4

Post by tobetter »

Rens wrote:
Tue Jan 18, 2022 7:26 pm
@tobetter
How do you mean? The microchip device is a microcontroller that is able to send a message over the RS485 interface. i am only able to set it with a wire high or low.

[Note:]
This setup works fine with reading and writing via uart over the RX and TX pin connected between the CP2102 and the Odroid C4.

The RTS and CTS pins are not used then, i am only trying to use the RTS pin as a flow controller for the RS485 transmitter flow control pin. Toggling this manually by hand does not work fast enough, because i am trying to send a response on the message.
So do you mean you set the signal as LOW from Microchip device and the signal is connected to CTS pin on ODROID-C4?
Can you try to send a message from the microcontroller to see if ODROID-C4 receives a data after connecting the signal CTS to GND on ODROID-C4?

Rens
Posts: 40
Joined: Wed Dec 01, 2021 6:27 pm
languages_spoken: english
ODROIDs: Odroid C4
Has thanked: 4 times
Been thanked: 0
Contact:

Re: Uart flow control for rs485 transmitter on the Odroid C4

Post by Rens »

@tobetter

The microcontroller only sends the RS485 signal via 2 data lines in the cable. furthermore this cable consist of a VCC and GND, but nothing else.
No CTS signal is send to the Odroid C4, which would not matter much i suspect since the exact same code worked for the basic uart setup with RX and TX pins (and same .dtbo file).

No message is received on the odroid when CTS is connected to the ground
(1) works just fine, i dont use the RTS or CTS pins, just reading and writing via uart.
(2) no messages are comming in when i try to read.
schematic.jpeg
schematic.jpeg (115.87 KiB) Viewed 129 times
[Note:]
The CP2102 displays alle messages i am sending from the microcontroller, but the odroid shows nothing.

User avatar
tobetter
Posts: 8896
Joined: Mon Feb 25, 2013 10:55 am
languages_spoken: Korean, English
ODROIDs: Many
Location: Paju, South Korea
Has thanked: 521 times
Been thanked: 1421 times
Contact:

Re: Uart flow control for rs485 transmitter on the Odroid C4

Post by tobetter »

@Rens, thanks for the drawing which makes me more understand what you are going to do. Would you be able to clarify more which RS485 transmitter is connected and what pins in number are connected between the transmitter and ODROID-C4? I suspect that CTS pin is not properly working when you use the .dtbo regardless RTS, Or CTS/RTS on ODROID-C4 is swapped?

Rens
Posts: 40
Joined: Wed Dec 01, 2021 6:27 pm
languages_spoken: english
ODROIDs: Odroid C4
Has thanked: 4 times
Been thanked: 0
Contact:

Re: Uart flow control for rs485 transmitter on the Odroid C4

Post by Rens »

@tobetter
I am using the https://www.ti.com/lit/ds/symlink/sn75176a.pdf SN75176. Where due to a lvl controller i can just control it with just a single pin flow controller, a RX pin, a TX pin and a gnd.
I connected the RX tot the R (output) and the TX to the D (input).

The flow control pin works like it is suppose to. Low for reading data and high for writing data.

[Edit:]
I executed my own program which sets the uart setting with termios and now i can receive data, only in my program i receive junky data. But the rts pin still stay the same, goes low when the uart slave or master is active.

User avatar
tobetter
Posts: 8896
Joined: Mon Feb 25, 2013 10:55 am
languages_spoken: Korean, English
ODROIDs: Many
Location: Paju, South Korea
Has thanked: 521 times
Been thanked: 1421 times
Contact:

Re: Uart flow control for rs485 transmitter on the Odroid C4

Post by tobetter »

Thank you for the datasheet. If you have wired TX of C4 to D (4) of SN75176 and RX to R (1), also /RE (2) and DE (3) are tied to RTS of C4, you would need to invert the signal of RTS. If my understanding is correct, RTS goes low when a data is transmitted by a sender. CTS of C4 must be tied to GND or ignored by software.

You could check the status of RTS when send a data from C4, it must be low only when a data is sent if hardware flow control works.

Rens
Posts: 40
Joined: Wed Dec 01, 2021 6:27 pm
languages_spoken: english
ODROIDs: Odroid C4
Has thanked: 4 times
Been thanked: 0
Contact:

Re: Uart flow control for rs485 transmitter on the Odroid C4

Post by Rens »

tobetter wrote:
Tue Jan 18, 2022 9:42 pm
Thank you for the datasheet. If you have wired TX of C4 to D (4) of SN75176 and RX to R (1), also /RE (2) and DE (3) are tied to RTS of C4, you would need to invert the signal of RTS. If my understanding is correct, RTS goes low when a data is transmitted by a sender. CTS of C4 must be tied to GND or ignored by software.

You could check the status of RTS when send a data from C4, it must be low only when a data is sent if hardware flow control works.
yeah that is exactly how i would expect the behavior of the rts pin. Sadly the pin goes Low the moment i issue open() and goes high when i close() the uart connection. This is the same for using cat /dev/ttyS1 (slave listener) and cat /dev/random > /dev/ttyS1 for master writing, with both commands i see the RTS pin go low and after is ctrl + C the program it toggles back to High.

User avatar
tobetter
Posts: 8896
Joined: Mon Feb 25, 2013 10:55 am
languages_spoken: Korean, English
ODROIDs: Many
Location: Paju, South Korea
Has thanked: 521 times
Been thanked: 1421 times
Contact:

Re: Uart flow control for rs485 transmitter on the Odroid C4

Post by tobetter »

Rens wrote:
Tue Jan 18, 2022 9:51 pm
tobetter wrote:
Tue Jan 18, 2022 9:42 pm
Thank you for the datasheet. If you have wired TX of C4 to D (4) of SN75176 and RX to R (1), also /RE (2) and DE (3) are tied to RTS of C4, you would need to invert the signal of RTS. If my understanding is correct, RTS goes low when a data is transmitted by a sender. CTS of C4 must be tied to GND or ignored by software.

You could check the status of RTS when send a data from C4, it must be low only when a data is sent if hardware flow control works.
yeah that is exactly how i would expect the behavior of the rts pin. Sadly the pin goes Low the moment i issue open() and goes high when i close() the uart connection. This is the same for using cat /dev/ttyS1 (slave listener) and cat /dev/random > /dev/ttyS1 for master writing, with both commands i see the RTS pin go low and after is ctrl + C the program it toggles back to High.
Do you have any progress?

Rens
Posts: 40
Joined: Wed Dec 01, 2021 6:27 pm
languages_spoken: english
ODROIDs: Odroid C4
Has thanked: 4 times
Been thanked: 0
Contact:

Re: Uart flow control for rs485 transmitter on the Odroid C4

Post by Rens »

tobetter wrote:
Wed Jan 19, 2022 10:49 pm
Rens wrote:
Tue Jan 18, 2022 9:51 pm
tobetter wrote:
Tue Jan 18, 2022 9:42 pm
Thank you for the datasheet. If you have wired TX of C4 to D (4) of SN75176 and RX to R (1), also /RE (2) and DE (3) are tied to RTS of C4, you would need to invert the signal of RTS. If my understanding is correct, RTS goes low when a data is transmitted by a sender. CTS of C4 must be tied to GND or ignored by software.

You could check the status of RTS when send a data from C4, it must be low only when a data is sent if hardware flow control works.
yeah that is exactly how i would expect the behavior of the rts pin. Sadly the pin goes Low the moment i issue open() and goes high when i close() the uart connection. This is the same for using cat /dev/ttyS1 (slave listener) and cat /dev/random > /dev/ttyS1 for master writing, with both commands i see the RTS pin go low and after is ctrl + C the program it toggles back to High.
Do you have any progress?
No not yet, i got the flue currently and i don't have the Odroid with me. I will try next week.

User avatar
tobetter
Posts: 8896
Joined: Mon Feb 25, 2013 10:55 am
languages_spoken: Korean, English
ODROIDs: Many
Location: Paju, South Korea
Has thanked: 521 times
Been thanked: 1421 times
Contact:

Re: Uart flow control for rs485 transmitter on the Odroid C4

Post by tobetter »

Rens wrote:
Thu Jan 20, 2022 5:50 pm
tobetter wrote:
Wed Jan 19, 2022 10:49 pm
Rens wrote:
Tue Jan 18, 2022 9:51 pm
tobetter wrote:
Tue Jan 18, 2022 9:42 pm
Thank you for the datasheet. If you have wired TX of C4 to D (4) of SN75176 and RX to R (1), also /RE (2) and DE (3) are tied to RTS of C4, you would need to invert the signal of RTS. If my understanding is correct, RTS goes low when a data is transmitted by a sender. CTS of C4 must be tied to GND or ignored by software.

You could check the status of RTS when send a data from C4, it must be low only when a data is sent if hardware flow control works.
yeah that is exactly how i would expect the behavior of the rts pin. Sadly the pin goes Low the moment i issue open() and goes high when i close() the uart connection. This is the same for using cat /dev/ttyS1 (slave listener) and cat /dev/random > /dev/ttyS1 for master writing, with both commands i see the RTS pin go low and after is ctrl + C the program it toggles back to High.
Do you have any progress?
No not yet, i got the flue currently and i don't have the Odroid with me. I will try next week.
Ok, @lsc1117 and myself studied UART signals with ODROID-H2 (x86) to learn how generic Linux box does work and read many articles regarding to UART and RS485, let me share a couple of interesting pages. Our observation with ODROID-H2 (Intel x86-64) is that RTS signal goes low when a tty device open and goes high when it's closed, this is the same behavior you found with ODROID-C4. Which means that the UART driver of ODROID-C4 is normal or compatible with generic Linux OS. After having more research with a test application by @lsc1117, we found that RTS goes high when data pool of receiver is full. In other word, RTS is low when receiving buffer is available to receive, otherwise high.

However this does not meet your requirement to interface with RS485. And from the articles above explained about RTS control which you might need to use when interfacing to RS485, this feature is not supported by Linux OS - AFAIK - this behavior is different with the hardware flow control what we understand with RTS/CTS. RTS control switches the state of RTS when transmitting a data for half duplex mode. Article also explained that this is possible with a code in user space by switching RTS signal when before and after calling a transmit function. Since this could make data flow become slower, the other way is to modify a driver to switch RTS whenever a data is transmitted. Actually this is the way I understand how RTS works in serial communication but apparently it's not. So we may need to study the device driver if RTS can be switched in kernel.

This is what I understand so far...maybe I would be wrong...
Please do read the articles regarding to RTS control and share your thoughts. :)

Post Reply

Return to “Hardware and peripherals”

Who is online

Users browsing this forum: No registered users and 1 guest