void Init_RS485_Pins() {
// FC2 -> P1_24
const uint32_t Rs485_Rx =
(IOCON_PIO_FUNC1 | IOCON_PIO_MODE_INACT | IOCON_PIO_SLEW_STANDARD |
IOCON_PIO_INV_DI | IOCON_PIO_DIGITAL_EN | IOCON_PIO_OPENDRAIN_DI);
IOCON_PinMuxSet(IOCON, 1U, 24U, Rs485_Rx);
// FC2 -> P1_25
const uint32_t Rs485_Tx =
(IOCON_PIO_FUNC1 | IOCON_PIO_MODE_INACT | IOCON_PIO_SLEW_STANDARD |
IOCON_PIO_INV_DI | IOCON_PIO_DIGITAL_EN | IOCON_PIO_OPENDRAIN_DI);
IOCON_PinMuxSet(IOCON, 1U, 25U, Rs485_Tx);
// FC2 -> P1_27
const uint32_t Rs485_RTS =
(IOCON_PIO_FUNC1 | IOCON_PIO_MODE_INACT | IOCON_PIO_SLEW_STANDARD |
IOCON_PIO_INV_DI | IOCON_PIO_DIGITAL_EN | IOCON_PIO_OPENDRAIN_DI);
IOCON_PinMuxSet(IOCON, 1U, 27U, Rs485_RTS);
}
and your piece of code I put the same way, something like this
void RS485_Init() {
usart_config_t config;
/*
* config.baudRate_Bps = 115200U;
* config.parityMode = kUSART_ParityDisabled;
* config.stopBitCount = kUSART_OneStopBit;
* config.loopback = false;
* config.enableTxFifo = false;
* config.enableRxFifo = false;
*/
USART_GetDefaultConfig(&config);
config.baudRate_Bps = RS485_BAUD_RATE;
config.enableTx = true;
config.enableRx = true;
/* attach main clock divide to FLEXCOMM2*/
CLOCK_AttachClk(kFRO12M_to_FLEXCOMM2);
USART_Init(RS485, &config, RS485_CLK_FREQ);
RS485->CFG |= USART_CFG_OESEL(1); /* if enabled, use RTS signal for RS-485 transceiver */
RS485->CFG |= USART_CFG_OEPOL(1); /* 1: the output enable signal is high active */
RS485->CFG |= USART_CFG_OETA(1); /* output enable turnaround time: if set, the output enable signal remains asserted for 1 char time after the end of the last bit */
USART_EnableInterrupts(RS485, kUSART_RxLevelInterruptEnable);
EnableIRQ(FLEXCOMM2_IRQn);
}
first i call Init_RS485_Pins() and then RS485_Init()
I have written a normal transmit code which runs in a task with period 1 sec, and in the recv interrupt it just loopbacks whatever it recvs.
When I keep P1_27(RTS pin) floating I get Tx properly, but Rx loopback doesnt work(please tell me why even Tx should work in this case?)
Then when I mux P1_27 with Re and De of my max-485, I get garbage values for Tx and loopback works too, but obviously thats garbage too
Please help on this
Another thing, in ur reply you stated that
With writing the CFG register I configure the UART to change the RE pin accordingly, to enable 'Tx' mode, otherwise being always in Rx mode.
Does including those 3 lines in init function do the Tx and Rx mode?