Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Add] UART RS485 mode #447

Closed
xiaguangbo opened this issue Jul 4, 2024 · 4 comments
Closed

[Add] UART RS485 mode #447

xiaguangbo opened this issue Jul 4, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@xiaguangbo
Copy link
Contributor

RTS for RS485 Half-Duplex Mode manages DE/~RE, tested

in esp-idf-hal/src/uart.rs: fn new_common

... 
esp!(unsafe {
        uart_driver_install(
            UART::port(),
            if rx.is_some() {
                config.rx_fifo_size as _
            } else {
                0
            },
            if tx.is_some() {
                config.tx_fifo_size as _
            } else {
                0
            },
            config.queue_size as _,
            queue.map(|q| q as *mut _).unwrap_or(ptr::null_mut()),
            InterruptType::to_native(config.intr_flags) as i32,
        )
    })?;

    esp!(unsafe {uart_set_mode(UART::port(), uart_mode_t_UART_MODE_RS485_HALF_DUPLEX)})?; // add this

    // Configure interrupts after installing the driver
    // so it won't get overwritten.
    let usr_intrs = config.event_config.clone().into();
    esp!(unsafe { uart_intr_config(UART::port(), &usr_intrs as *const _) })?;
... 
@Vollbrecht
Copy link
Collaborator

If you want to work on RS485 support in the public API feel free to send a PR. Though we have to be mindful to not break the usage for everyone else.

@Vollbrecht Vollbrecht added the enhancement New feature or request label Jul 7, 2024
@xiaguangbo
Copy link
Contributor Author

@Vollbrecht update, #456

@github-project-automation github-project-automation bot moved this from Todo to Done in esp-rs Jul 14, 2024
@DaneSlattery
Copy link
Contributor

@xiaguangbo thank you for this, I was manually toggling the direction pin on an RS485 driver before this.

Is it possible to use a different pin for this?

@xiaguangbo
Copy link
Contributor Author

@xiaguangbo thank you for this, I was manually toggling the direction pin on an RS485 driver before this.

Is it possible to use a different pin for this?

The master has merge last change, If crate.io esp-idf-hal not update: copy master src/uart.rs cover local code, cleaned rebuild
Link this, rts/dir can be any pin.

let uart = UartDriver::new(
                            peripherals.uart1,
                            peripherals.pins.gpio5,
                            peripherals.pins.gpio6,
                            Option::<AnyIOPin>::None,
                            Some(peripherals.pins.gpio7), // rts/dir
                            &config::Config::new()
                                .mode(config::Mode::RS485HalfDuplex)
                                .baudrate(baudrate),
                        );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Archived in project
Development

No branches or pull requests

3 participants