This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

BEAGL-BONE-BLACK: Help to create dts file for rs485 half duplex in uart2

Part Number: BEAGL-BONE-BLACK
Other Parts Discussed in Thread: OPA362, TPD12S015

Hello,
I am trying to implement a dts file for a half duplex communication with modbus devices via rs485. I have a custom beaglebone based in beaglebone black with a rs485 input. I want to create a dts file to control properly the rts signal. The rts signal its responsible to control if my device gonna read or write in the channel (both functions in the same time dont work due too half duplex communication). For now i have created a dts file, a script to send a command via the port and i have a logic analyzer to see what happens. The problem i have its that the rts signal its way off. It should be low and when i am sending the command(tx) become high, until the command send and become low again to read the response(no response for now as i am connected with the logic analyzer). Can you provide any dts file for this usage or explain what i should do?
I am providing a link with the dts and script files and a screenshot from logic analyzer (https://we.tl/t-OxwD2nOlnq).
Thank you in advance,
Panos.

  • Hi Panos,

    The link you provided is blocked by TI firewall, so I cannot access it. Can you please attach them to this thread.

    Do you mean the RTS signal polarity is reversed?

  • Which kernel version do you use? Which kernel UART driver do you use, is it 8250_omap.c or omap_serial.c?

  • I cant upload the files, thats why i provided a we transer link, sorry fot that,I am sending you the files in txt.


    0207.dtsfile.txt
    /*      pins
    function        GPIO        BB PINS
    RXD		        GPIO0_2		P9.22
    TXD		        GPIO0_3		P9.21
    LCD_DATA9/RTSN	GPIO2_15	P8.38*/
    
    /dts-v1/;
    /plugin/;
    
    #include <dt-bindings/board/am335x-bbw-bbb-base.h>
    #include <dt-bindings/pinctrl/am33xx.h>
    
    / {
    	compatible = "ti,beaglebone", "ti,beaglebone-black", "ti,beaglebone-green";
    
    	// identification
    	part-number = "BB-UART2-RS485";
    	version = "00A4";
    
    	// resources this cape uses
    	exclusive-use =						//edw ta dika mas pins 8a htan
    		"P9.21",		// uart2_txd	//GPIO0_3
    		"P9.22",		// uart2_rxd	//GPIO0_2
    		"P8.38",		// uart2_rtsn	//GPIO2_15	//uart2_rtsn
    
    		"uart2";		// hardware ip used
    
    	/*
    	 * Helper to show loaded overlays under: /proc/device-tree/chosen/overlays/
    	 */
    	fragment@0 {
    		target-path="/";
    		__overlay__ {
    
    			chosen {
    				overlays {
    					BB-UART2-RS485-00A4 = __TIMESTAMP__;
    				};
    			};
    		};
    	};
    
    	/*
    	 * Free up the pins used by the cape from the pinmux helpers.
    	 */
    	fragment@1 {
    		target = <&ocp>;
    		__overlay__ {
    			P9_21_pinmux { status = "disabled"; };
    			P9_22_pinmux { status = "disabled"; };
    			P8_38_pinmux { status = "disabled"; }; 
    		};
    	};
    
    	fragment@2 {
    		target = <&am33xx_pinmux>;
    		__overlay__ {
    			bb_uart2_rs485_pins: pinmux_bb_uart2_rs485_pins {
    				pinctrl-single,pins = <
    					BONE_P9_21 (PIN_OUTPUT | MUX_MODE1)	
    					BONE_P9_22 (PIN_INPUT  | MUX_MODE1)	
    					BONE_P8_38 (MUX_MODE6) //0x06
    				>;
    			};
    		};
    	};
    
    	fragment@3 {
    		target = <&uart2>;
    		__overlay__ {
    			status = "okay";
    			pinctrl-names = "default";
    			pinctrl-0 = <&bb_uart2_rs485_pins>;
    			rs485-rts-delay = <0 0>;
    
    			rts-gpio = <&gpio2 15 1>; /*  GPIO_ACTIVE_HIGH>; */
    			rs485-rts-active-high;
        //      // rs485-rts-before-send = <&gpio2 15 1>;
    	// 		// rs485-rts-after-send = <&gpio2 15 0>;
    	// 		// rs485-rts-after-recv = <&gpio2 15 1>;
    			linux,rs485-enabled-at-boot-time;
    		};
    	};
    };
    
    scriptForTesting.txt
    import serial
    import struct
    from base64 import encode
    
    # open serial port
    #ser = serial.Serial('/dev/ttyS2', 9600, timeout=1)
    ser = serial.Serial(
                '/dev/ttyS2',
                baudrate=9600,
                bytesize=8,
                timeout=1,
                stopbits=serial.STOPBITS_ONE,
                parity=serial.PARITY_NONE
            )
    # configure RS485 settings
    command = [1, 4, 0, 1, 0, 2, 32, 11]
    data = bytearray(command)
    
    # ser.setRTS(False)
    ser.write(data)
    #ser.setDTR(True)
    #ser.write(b'\x01\x04\x00\x01\x00\x02\x20\x0B')
    ser.flush()
    # ser.setRTS(True)
    #ser.setDTR(False)
    
    # read response
    response = ser.read(9)
    # temperature = response[3] + response[4]
    # humidity = response[5] + response[6]
    
    # (temp,) = struct.unpack(">h", temperature)
    # print("temperature " + str(temp))
    # (humi,) = struct.unpack(">h", humidity)
    # print("humidity " + str(humi))
    print("Temp and Humid Read.")
    
    # print response
    print(response)
    
    # close serial port
    ser.close()
    

  • The kernel i use its this: Linux arm 4.19.94-ti-r42 #1bionic SMP PREEMPT Tue Mar 31 19:46:51 UTC 2020 armv7l armv7l armv7l GNU/Linux
    and the omap i believe its 8250 but i am not totally sure, if you can check it here:
    config of kernel:
    CONFIG_SERIAL_8250=y
    # CONFIG_SERIAL_8250_DEPRECATED_OPTIONS is not set
    # CONFIG_SERIAL_8250_FINTEK is not set
    CONFIG_SERIAL_8250_CONSOLE=y
    # CONFIG_SERIAL_8250_DMA is not set
    CONFIG_SERIAL_8250_NR_UARTS=6
    CONFIG_SERIAL_8250_RUNTIME_UARTS=6
    # CONFIG_SERIAL_8250_EXTENDED is not set
    # CONFIG_SERIAL_8250_ASPEED_VUART is not set
    CONFIG_SERIAL_8250_FSL=y
    # CONFIG_SERIAL_8250_DW is not set
    # CONFIG_SERIAL_8250_EM is not set
    # CONFIG_SERIAL_8250_RT288X is not set
    CONFIG_SERIAL_8250_OMAP=y
    CONFIG_SERIAL_8250_OMAP_TTYO_FIXUP=y
    # Non-8250 serial port support
    CONFIG_MEDIA_TUNER_TDA18250=m

    omap:

    CONFIG_OMAP4_DSS_HDMI_CEC=y
    CONFIG_OMAP5_DSS_HDMI=y
    # CONFIG_OMAP2_DSS_SDI is not set
    # CONFIG_OMAP2_DSS_DSI is not set
    CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK=0
    CONFIG_OMAP2_DSS_SLEEP_AFTER_VENC_RESET=y
    # OMAPDRM External Display Device Drivers
    # CONFIG_DRM_OMAP_ENCODER_OPA362 is not set
    CONFIG_DRM_OMAP_ENCODER_TPD12S015=y
    CONFIG_DRM_OMAP_DRA7EVM_ENCODER_TPD12S015=y
    CONFIG_DRM_OMAP_CONNECTOR_HDMI=y
    # CONFIG_DRM_OMAP_CONNECTOR_ANALOG_TV is not set
    # CONFIG_DRM_OMAP_PANEL_DSI_CM is not set
    # CONFIG_DRM_OMAP_PANEL_SONY_ACX565AKM is not set
    # CONFIG_DRM_OMAP_PANEL_LGPHILIPS_LB035Q02 is not set
    # CONFIG_DRM_OMAP_PANEL_SHARP_LS037V7DW01 is not set
    # CONFIG_DRM_OMAP_PANEL_TPO_TD028TTEC1 is not set
    # CONFIG_DRM_OMAP_PANEL_TPO_TD043MTEA1 is not set
    # CONFIG_DRM_OMAP_PANEL_NEC_NL8048HL11 is not set
    CONFIG_SND_SOC_OMAP_DMIC=y
    CONFIG_SND_SOC_OMAP_MCBSP=y
    CONFIG_SND_SOC_OMAP_MCPDM=y
    CONFIG_SND_SOC_OMAP_HDMI=y
    CONFIG_USB_EHCI_HCD_OMAP=y
    # CONFIG_USB_MUSB_OMAP2PLUS is not set
    CONFIG_USB_DWC3_OMAP=y
    # CONFIG_MMC_OMAP is not set
    CONFIG_MMC_OMAP_HS=y
    CONFIG_MMC_SDHCI_OMAP=y
    CONFIG_RTC_DRV_OMAP=y
    CONFIG_DMA_OMAP=y
    CONFIG_HWSPINLOCK_OMAP=y
    CONFIG_OMAP_DM_TIMER=y
    CONFIG_OMAP2PLUS_MBOX=y
    CONFIG_OMAP_MBOX_KFIFO_SIZE=256
    CONFIG_OMAP_IOMMU=y
    # CONFIG_OMAP_IOMMU_DEBUG is not set
    CONFIG_OMAP_REMOTEPROC=m
    CONFIG_OMAP_REMOTEPROC_WATCHDOG=y
    CONFIG_OMAP_GPMC=y
    # CONFIG_OMAP_GPMC_DEBUG is not set
    CONFIG_PWM_OMAP_DMTIMER=y
    CONFIG_OMAP_IRQCHIP=y
    CONFIG_OMAP_CONTROL_PHY=y
    CONFIG_OMAP_USB2=y
    CONFIG_FS_IOMAP=y
    CONFIG_CRYPTO_DEV_OMAP=y
    CONFIG_CRYPTO_DEV_OMAP_SHAM=y
    CONFIG_CRYPTO_DEV_OMAP_AES=y
    CONFIG_CRYPTO_DEV_OMAP_DES=y
    CONFIG_GENERIC_PCI_IOMAP=y