Am not sure how to use RTS and CTS both in hardware and software and need help regarding the same.
When I do this
This too doesnt clearly state the implentation.
Any help or support is appreciated
Thanks
解決済! 解決策の投稿を見る。
You might have a look at one of my projects posted here:
https://mcuoneclipse.com/2022/12/31/controlling-an-ev-charger-with-modbus-rtu/
I'm using that both for LPC854 and LPC55S69. Check the McuUART485.c, which has a setting
McuUart485_CONFIG_USE_HW_OE_RTS
which defines if you want to use normal GPIO for the RE signal or the hardware RTS.
I only noticed that on LPC using a GPIO is faster:
than using the hardware RTS pin, maybe there is a delay I missed to configure in hardware.
Anyway, both works fine.
The 'magic' trick is to configure the UART using the following flags (they are not accessible through the SDK, so I do it directly:
#if McuUart485_CONFIG_USE_HW_OE_RTS
#if McuLib_CONFIG_CPU_IS_KINETIS /* Kinetis K22FN512 */
McuUart485_CONFIG_UART_DEVICE->MODEM |= UART_MODEM_TXRTSPOL(1); /* TXRTSPOL: 1: transmitter RTS polarity is active high */
McuUart485_CONFIG_UART_DEVICE->MODEM |= UART_MODEM_TXRTSE(1); /* TXRTSE: Transmitter request-to-send enable, 1: RTS asserted before start bit is transmitted and deasserted after stop bit */
#elif McuLib_CONFIG_CPU_IS_LPC /* LPC845 or LPC55S69 */
McuUart485_CONFIG_UART_DEVICE->CFG |= USART_CFG_OESEL(1); /* if enabled, use RTS signal for RS-485 transceiver */
McuUart485_CONFIG_UART_DEVICE->CFG |= USART_CFG_OEPOL(1); /* 1: the output enable signal is high active */
McuUart485_CONFIG_UART_DEVICE->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 */
#endif
#endif
I hope this helps, otherwise I would write up a quick article on my blog (if time permits).
You can find the McuLib here: https://github.com/ErichStyger/McuOnEclipseLibrary/tree/master/lib
Erich
I flashed ur project on my board
I used "rs send hi", (dont know why it didnt show up on the serial monitor)
On the RS485 recv side it shows this
To answer your above question -> without the transceiver, that is using normal uart my flexcom 2 worked, and for pull-up thing, I had used the same transiever for lpc2148 and it worked without the need for pullup
The reason why you don't see the text in the console view is because it does not implement 'local echo'. This could be configured in other terminals or in the McuShell itself.
possible reasons:
A multi-meter does not show you much, especially it won't show glitches or fast changes. You need to check it with an oscilloscope or or with a logic analyzer (best one which can show analog signals too). See the screenshot in my blog as an example.
I noticed a strange thing
Firstly, this is my code for rs485
This is what i got on serial monitor
The very first time `RS485_Transmit()` is called it shows output correctly, after that its just random characters
(PS: RS485_Transmit() is in while loop with delay of 1sec between two consecutive function calls)
a) have a look at the signals with your oscilloscope
b) just for making things simpler: for sending you don't need the interrupt, so for testing I would disable/not using it.
Hey @ErichStyger
Thank you for dedicating your time in writing the above blog. Help a lot
Please check my pin config in the attached image.
Also I have included the 3 lines of code for RTS.
But again, the problem am facing is garbage value displayed on serial terminal.
(PS: baudrate and other serial settings are not the issue, as the same worked when i used normal uart instead of rs-485)
Maybe your RS-485 transceiver requires a pull-up? Have you checked the signals without the transceiver?
Your muxing looks ok.
Other than that: can you try my code with the EVK using that different FLEXCOM?
Just in case, this is the usual circuit I'm using:
I got the point now
Am using flexcomm2 which means, this is my rs485_init pins
Just in case: I have described my setup here: https://mcuoneclipse.com/2023/08/03/rs-485-with-nxp-lpc55s69/
The three lines configure the RTS pin to go high during sending, and pulling it low (listening mode) otherwise. That's all what it does.
@ErichStyger Thanks for the info
But I cannot see where you have enabled the hardware flow control
For lpc55s69 there is dedicated rts pin for every uart, and also in config structure there is this member
Hi @manasvb ,
the 'magic sauce' is with that code piece I shared, plus muxing the RTS pin:
With RS-485, I cannot use 'full' handshaking, as it would require the CTS pin too. But all what I need is the RTS which is connected to both the RE pins of the receiver. 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.
If you want to try it out: I stripped down our university research project and published an example on GitHub you can see it in action:
Examples/MCUXpresso/LPC55S69-EVK/LPC55S69_RS-485
I hope this helps,
Erich
You might have a look at one of my projects posted here:
https://mcuoneclipse.com/2022/12/31/controlling-an-ev-charger-with-modbus-rtu/
I'm using that both for LPC854 and LPC55S69. Check the McuUART485.c, which has a setting
McuUart485_CONFIG_USE_HW_OE_RTS
which defines if you want to use normal GPIO for the RE signal or the hardware RTS.
I only noticed that on LPC using a GPIO is faster:
than using the hardware RTS pin, maybe there is a delay I missed to configure in hardware.
Anyway, both works fine.
The 'magic' trick is to configure the UART using the following flags (they are not accessible through the SDK, so I do it directly:
#if McuUart485_CONFIG_USE_HW_OE_RTS
#if McuLib_CONFIG_CPU_IS_KINETIS /* Kinetis K22FN512 */
McuUart485_CONFIG_UART_DEVICE->MODEM |= UART_MODEM_TXRTSPOL(1); /* TXRTSPOL: 1: transmitter RTS polarity is active high */
McuUart485_CONFIG_UART_DEVICE->MODEM |= UART_MODEM_TXRTSE(1); /* TXRTSE: Transmitter request-to-send enable, 1: RTS asserted before start bit is transmitted and deasserted after stop bit */
#elif McuLib_CONFIG_CPU_IS_LPC /* LPC845 or LPC55S69 */
McuUart485_CONFIG_UART_DEVICE->CFG |= USART_CFG_OESEL(1); /* if enabled, use RTS signal for RS-485 transceiver */
McuUart485_CONFIG_UART_DEVICE->CFG |= USART_CFG_OEPOL(1); /* 1: the output enable signal is high active */
McuUart485_CONFIG_UART_DEVICE->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 */
#endif
#endif
I hope this helps, otherwise I would write up a quick article on my blog (if time permits).
You can find the McuLib here: https://github.com/ErichStyger/McuOnEclipseLibrary/tree/master/lib
Erich