Redguy
Posts: 3
Joined: Mon Nov 28, 2016 10:19 am

Modify settings SC16IS752 to activate RS485 features ??

Mon Jan 09, 2017 2:19 pm

I hooked up some SC16IS752 (Dual Uart chip with I2C/SPI connection) to my raspberry pi, and got them to work through the overlay system.The chips provide some additional RS232 interfaces for various systems.


The SC16IS752 also supports RS485 mode, which takes care of the direction control needed to switch between send/receive mode on the RS485 transceiver for half-duplex RS-485. I would much prefer this over using a separate GPIO pin to do this in software.

According to the datasheet (page 33) this can be enabled by setting bit 4 of the EFCR register. Once this is set, the UART will toggle the RTS pin on/off to switch between send and receive.

How can I set this register ? Can this be done through the overlay system by adding some extra settings to the .DTS file and compile a .DTB ?

If so, how ? From what I see in the DTB file (see below), it mainly deals with the connection between the chip and the raspi, naming the SPI interface, IRQ pin to be used, clockrate set etc. Not with the internal settings of the UART chip.

Code: Select all

/dts-v1/;
/plugin/;

/ {

	compatible = "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709";

	[email protected] {
		target = <&gpio>;
		__overlay__ {
			spi1_pins: spi1_pins {
				brcm,pins = <19 20 21>;
				brcm,function = <3>; /* alt4 */
			};



			spi1_cs_pins: spi1_cs_pins {
				brcm,pins = <18>;
				brcm,function = <1>; /* output */

			};
		};
	};

	[email protected] {

		target = <&spi1>;
		frag1: __overlay__ {
			#address-cells = <1>;
			#size-cells = <0>;
			pinctrl-names = "default";
			pinctrl-0 = <&spi1_pins &spi1_cs_pins>;
			cs-gpios = <&gpio 18 1>;
			status = "okay";

			sc16is752: [email protected] {
				compatible = "nxp,sc16is752";
				reg = <0>; /* CE0 */
				clocks = <&sc16is752_clk>;
				interrupt-parent = <&gpio>;
				interrupts = <24 2>; /* IRQ_TYPE_EDGE_FALLING */
				#gpio-controller;
				#gpio-cells = <2>;
				spi-max-frequency = <4000000>;

				sc16is752_clk: sc16is752_clk {
					compatible = "fixed-clock";
					#clock-cells = <0>;
					clock-frequency = <14745600>;

				};
			};
		};
	};



	[email protected] {

		target = <&aux>;
		__overlay__ {
			status = "okay";
		};
	};

    __overrides__ {
      int_pin = <&sc16is752>,"interrupts:0";
    };

};

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7443
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Modify settings SC16IS752 to activate RS485 features ??

Mon Jan 09, 2017 3:08 pm

Please don't double post - viewtopic.php?f=107&t=146908&start=25#p1095082

Find the driver source - https://github.com/raspberrypi/linux/bl ... c16is7xx.c
Note that it has that bit defined as SC16IS7XX_EFCR_AUTO_RS485_BIT
Note that it gets set if the config has SER_RS485_ENABLED set
Observe that the use of that flag is documented in https://github.com/raspberrypi/linux/bl ... -rs485.txt, including an example of how to set that flag from userspace. It also includes a reference to the device tree bindings at https://github.com/raspberrypi/linux/bl ... /rs485.txt

Code: Select all

	usart0: [email protected] {
		compatible = "atmel,at91sam9260-usart";
		reg = <0xfff8c000 0x4000>;
		interrupts = <7>;
		atmel,use-dma-rx;
		atmel,use-dma-tx;
		linux,rs485-enabled-at-boot-time; <<<<<<<<<
		rs485-rts-delay = <0 200>;		// in milliseconds
	};
Hopefully problem solved.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

kaamil1984
Posts: 1
Joined: Sun Sep 08, 2019 7:58 pm

Re: Modify settings SC16IS752 to activate RS485 features ??

Sun Sep 08, 2019 8:05 pm

Actually... I like this kind of double posting.

We have not read whole forum Sir 6by9! That other post has too broad title. How someone was supposed to find that?

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7443
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Modify settings SC16IS752 to activate RS485 features ??

Mon Sep 09, 2019 11:23 am

kaamil1984 wrote:
Sun Sep 08, 2019 8:05 pm
Actually... I like this kind of double posting.

We have not read whole forum Sir 6by9! That other post has too broad title. How someone was supposed to find that?
Posting the same question twice isn't helpful as you'll potentially waste people's time where they respond independently of each other on the different threads.

The OP did the more sensible thing in starting a new thread here as his question was diverging from the other thread.
What they didn't need to do was post the same question twice.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Return to “Interfacing (DSI, CSI, I2C, etc.)”