This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Can i change Rx, Tx pin of UART?

Hi, I made a PCB board nrf51822.

Because of my mistake, Rx, Tx pin was not cross connected to MCU.

So i want to change Rx <-> Tx pin.

In the example of ble_app_uart_s130_pca10028,

I change the below source code.

const app_uart_comm_params_t comm_params =
{
    RX_PIN_NUMBER,
    TX_PIN_NUMBER,
    RTS_PIN_NUMBER,
    CTS_PIN_NUMBER,
    APP_UART_FLOW_CONTROL_ENABLED,
    false,
    UART_BAUDRATE_BAUDRATE_Baud38400
};

to

const app_uart_comm_params_t comm_params =
{
    9,
    11,
    RTS_PIN_NUMBER,
    CTS_PIN_NUMBER,
    APP_UART_FLOW_CONTROL_ENABLED,
    false,
    UART_BAUDRATE_BAUDRATE_Baud38400
};

And upload the firmware on nrf51822,

The UART program in nRF Toolbox app is not work.

The error message is Error 6:The connection has timed out unexpectedly

Why this error is occur?

When i change the Tx, Rx pin physically(jumpper line) on the MCU,

ble_app_uart_s130_pca10028( not change tx, rx) work very well.

  • You can all the pins connected to the UART peripheral as you like. I do not know your value of RX_PIN_NUMBER and TX_PIN_NUMBER, but if you want to swap them, you just need to swap them in the app_uart_comm_params_t instance:

    const app_uart_comm_params_t comm_params =
    {
        RX_PIN_NUMBER,
        TX_PIN_NUMBER,
        RTS_PIN_NUMBER,
        CTS_PIN_NUMBER,
        APP_UART_FLOW_CONTROL_ENABLED,
        false,
        UART_BAUDRATE_BAUDRATE_Baud38400
    };
    

    Maybe you have done exactly that, but it is difficult to know as your second code snippet use magic number for the pins. If the only problem is swapped pins, then this is all you need to do.

    As you write about the nRF Toolbox app and an error message "Error 6:The connection has timed out unexpectedly", I assume you are testing BLE over UART using NUS? The error message indicates that the BLE connection has timed out, and is not directly related to UART. I suggest you first debug and fix your UART communication, then consider debug BLE (and NUS), as debugging several issues at once tend to make things more complicated than it has to.

  • Thanks for your answer. I don't know ablout NUS. Just, i use example code... The time out error occur when connect MCU tx to BLE rx by unsing rx tx swapped source code. Before the connection, paring is not problem. As soon as connect tx to rx, the error message printed and break the paring.

  • I have come across the same problem but with my custom board where my tx-rx pin are different.

    When I configure UART example from sdk peripheral with my custom board tx-rx pin value.

    It goes into error and my program does not run.

    Can I use virtual comp port example with different tx-rx pin.?

    Or I have to config uart0-uart1 ..??

  • Yes, you can use any pins with UART. You just have to configure the library/driver you use with the correct pin configuration. Please create a new question if you need more follow-up on this, and then also include which chip and SDK version you are using, as well as which library/driver and how you have configured it.

Related