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.
I want to interface RS485 transceiver with AM335x processor. I am using UART5 for this purpose. I have doubt regarding transmit Direction Enable (DE) signal connection for RS485 transceiver.
Can i use RTS signal as a gpio so that it can be assigned as UART5 DE ?
Hi,
Smrithy TR said:Can i use RTS signal as a gpio so that it can be assigned as UART5 DE ?
Yes, this approach is correct.
Also have a look at the following posts:
https://e2e.ti.com/support/arm/sitara_arm/f/791/t/160391
https://e2e.ti.com/support/embedded/linux/f/354/p/266128/932284#932284
Best Regards,
Yordan
Hi,
Thank you Yordan..
I have gone through the above links. And found that the changes mentioned in that links are already incorporated.
In dtb, the serial port (ttys5) is configured as follows
uart5_pins: pinmux_uart5_pins {
pinctrl-single,pins = <
0xD8 (PIN_INPUT | MUX_MODE6) /* lcd_data14.uart5_ctsn */
0xDC (PIN_OUTPUT_PULLDOWN | MUX_MODE6) /* lcd_data15.uart5_rtsn */
0xC4 (PIN_INPUT_PULLUP | MUX_MODE4) /* lcd_data9.uart5_rxd */
0xC0 (PIN_OUTPUT_PULLDOWN | MUX_MODE4) /* lcd_data8.uart5_txd */
>;
};
uart5: serial@481aa000 {
pinctrl-names = "default";
pinctrl-0 = <&uart5_pins>;
status = "okay";
rts-gpio = <&gpio0 11 GPIO_ACTIVE_HIGH>;
rs485-rts-active-high;
rs485-rts-delay = <1 1>;
linux,rs485-enabled-at-boot-time;
};
And in omap-serial.c, modified 'serial_omap_config_rs485' function as follows
/* Enable or disable the rs485 support */
static void
serial_omap_config_rs485(struct uart_port *port, struct serial_rs485 *rs485conf)
{
struct uart_omap_port *up = to_uart_omap_port(port);
unsigned long flags;
unsigned int mode;
int val;
int r = 0, gpioFlag = 1;
pm_runtime_get_sync(up->dev);
spin_lock_irqsave(&up->port.lock, flags);
/* Disable interrupts from this port */
mode = up->ier;
up->ier = 0;
serial_out(up, UART_IER, 0);
if(!(rs485conf->flags & SER_RS485_ENABLED))
{
if ((up->rs485.flags & SER_RS485_ENABLED) && (gpio_is_valid(up->rts_gpio)))
{
gpio_free(up->rts_gpio);
}
up->rs485 = *rs485conf;
gpioFlag = 0;
}
else if(!(up->rs485.flags & SER_RS485_ENABLED) ||
(up->rts_gpio != rs485conf->gpio_pin))
{
val = (rs485conf->flags & SER_RS485_RTS_AFTER_SEND) ? 1 : 0;
if (gpio_is_valid(rs485conf->gpio_pin))
{
r = gpio_request(rs485conf->gpio_pin, "RS485 TXE");
if (r) {
dev_warn(port->dev, "Could not request GPIO %d : %d\n",rs485conf->gpio_pin, r);
gpioFlag = 0;
}
r = gpio_direction_output(rs485conf->gpio_pin, val);
if (r) {
dev_warn(port->dev, "Could not drive GPIO %d : %d\n", rs485conf->gpio_pin, r);
gpio_free(rs485conf->gpio_pin);
gpioFlag = 0;
}
}
}
if (gpioFlag)
{
/* store new config */
up->rs485 = *rs485conf;
/*
* Just as a precaution, only allow rs485
* to be enabled if the gpio pin is valid
*/
up->rts_gpio = rs485conf->gpio_pin;
/* enable / disable rts */
val = (up->rs485.flags & SER_RS485_ENABLED) ?
SER_RS485_RTS_AFTER_SEND : SER_RS485_RTS_ON_SEND;
val = (up->rs485.flags & val) ? 1 : 0;
gpio_set_value(up->rts_gpio, val);
}
/* Enable interrupts */
up->ier = mode;
serial_out(up, UART_IER, up->ier);
spin_unlock_irqrestore(&up->port.lock, flags);
pm_runtime_mark_last_busy(up->dev);
pm_runtime_put_autosuspend(up->dev);
}
And ensured that this function is executing properly.
Still RS485 is not working if RTS pin is configured as UART5 DE.
But RS485 functionality of UART5 is fine if any other GPIO is configured as its DE.
Please let me know if any mistake is there in my code/dtb .