How to enable hardware flow control (RTS) for RS-485 usage?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to enable hardware flow control (RTS) for RS-485 usage?

6,175 Views
felix1
Contributor IV

To take evkbimxrt1050_freertos_lpuart for example, the flow control is disable by default. Using  MAX485 for RS-485 circuit design, it need to enable the hardware flow control for transfer direction (TX, RX).

Can you show me how to enable hardware flow control for RS-485 usage in this example?

Labels (1)
Tags (2)
0 Kudos
3 Replies

5,628 Views
simonecolombo
Contributor I

Hello, i have the same issue, i'm using 3 uart (3,4,5) and i need to use rts to controll the flow but is the same, i can receive because the rts pin is low, when i transmit i see the data on tx pin but the rts remains low!

i don't use the cts, only rts.

this is my code:

lpuart_config_t config2;

LPUART_GetDefaultConfig(&config2);
config2.baudRate_Bps = sys.MB_baud[0];
config2.enableTx = true;
config2.enableRx = true;
config2.enableRxRTS = true;

LPUART_Init(MB1, &config2, MB_CLK_FREQ);
LPUART_EnableInterrupts(MB1, kLPUART_RxDataRegFullInterruptEnable);
EnableIRQ(MB1_IRQn);
PRINTF("-MB1: enabled\r\n");

0 Kudos

5,628 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi Felix:

What you need to do is

1. initialize CTS/RTS pin in pin_mux.c/h.  By default, the two pins is not initialized.

2. enable CTS/RTS function in    devices/mimxrt1052/drviers/fsl_lpuart.c, please see below red lines

void LPUART_GetDefaultConfig(lpuart_config_t *config)
{
    assert(NULL != config);

    /* Initializes the configure structure to zero. */
    (void)memset(config, 0, sizeof(*config));

    config->baudRate_Bps  = 115200U;
    config->parityMode    = kLPUART_ParityDisabled;
    config->dataBitsCount = kLPUART_EightDataBits;
    config->isMsb         = false;
#if defined(FSL_FEATURE_LPUART_HAS_STOP_BIT_CONFIG_SUPPORT) && FSL_FEATURE_LPUART_HAS_STOP_BIT_CONFIG_SUPPORT
    config->stopBitCount = kLPUART_OneStopBit;
#endif
#if defined(FSL_FEATURE_LPUART_HAS_FIFO) && FSL_FEATURE_LPUART_HAS_FIFO
    config->txFifoWatermark = 0;
    config->rxFifoWatermark = 0;
#endif
#if defined(FSL_FEATURE_LPUART_HAS_MODEM_SUPPORT) && FSL_FEATURE_LPUART_HAS_MODEM_SUPPORT
    config->enableRxRTS = true;   // enable RXRTS
    config->enableTxCTS = true;   //enable RXRTS
    config->txCtsConfig = kLPUART_CtsSampleAtStart;
    config->txCtsSource = kLPUART_CtsSourcePin;
#endif
    config->rxIdleType   = kLPUART_IdleTypeStartBit;
    config->rxIdleConfig = kLPUART_IdleCharacter1;
    config->enableTx     = false;
    config->enableRx     = false;
}

Regards

Daniel

0 Kudos

5,627 Views
felix1
Contributor IV

1)  I enable the RTS, but disable the CTS, the RTS (Tx, Rx direction pin) is from high to low too early, so I can not send the "all" data to the rs-485 master.

 LPUART_GetDefaultConfig(&config);
 config.baudRate_Bps = ulBaudRate;
 config.parityMode = parity;
 config.enableRxRTS = true;
 //config.enableTxCTS = true;
 NVIC_SetPriority(RS485_LPUART_IRQn, 2);
 status = LPUART_Init(RS485_LPUART, &config, RS485_LPUART_CLK_FREQ);
2) If I enable both RTS and CTS, I can not get the input from rs-485.
Can you give me some suggestions?
0 Kudos