News:

;) This forum is the property of Proton software developers

Main Menu

Is it possible transfer signal RX1 to TX2 and vice versa?

Started by Frizie, Feb 24, 2024, 09:09 PM

Previous topic - Next topic

Frizie

Given: PIC18F46K22 / 64MHz / with bootloader

Would it be possible to transfer data directly from RX1 (USART1) to TX2 (USART2) and from RX2 (USART2) to TX1 (USART1) ?  ("Pipe"-mode)  :o

The situation I have is as follows:
On USART1 there is an UART<>USB converter (CP2102N).
On USART2 there is a HMI (Nextion touchpanel).
Normally the PIC communicates data via USB (USART1) with a laptop and the control and display is via the HMI.
The PIC program can eventually also be updated with this connection (via the bootloader).

To update the HMI, it would be nice if this could also be done via the same (CP2102) USB connection on the PCB  ;)

On the HMI you inform the PIC (by pressing a button on the HMI) that it should go in "pipe" mode.
After that, the PIC should then transfer the TX and RX update-data for the HMI directly to the HMI.
On this way the HMI can also be updated via the (CP2102) USB connection.

The baud rate is not high: 9600 Baud for all mentioned connections  :D

Would this be possible or am I overlooking something and shouldn't put any energy into it?  ???
Ohm sweet Ohm | www.picbasic.nl

diebobo

Frizie,

you can always do a software version of that .. Pseudo code.

passthrough:
   
   If USART1.RX = 1 then USART2.tx = 1 : else USART2.tx = 0
   If USART2.RX = 1 then USART1.tx = 1 : else USART1.tx = 0

goto passthrough

Or if you pic has 2 hardware uarts you can setup a int per uart when rx buffer = 1 byte then inmeditaly do a tx of that byte on the other uart..

JonW

I don't think that mcu has DMA, you can easily do a transfer in software, (within an interrupt routine) or use a hardware Tri-state buffer to connect output of the CP2102 to the RX HMI and control the mcu TX pin tris registers on the Uart to release the Pic to HMI TX, such that the connection from the CP2102 can drive the HMI RX directly from the buffer

If this is for an update on the HMI then I would probably opt for hardware to avoid any  firmware corruption and have the option to manually force the buffer and keep the MCU in reset.

Frizie

I'll think the hardware variant is indeed the best.

The Nextion HMI also has a microSD-card connection with a TFT file of the update for this kind of thing, but that does not always work.
In certain cases, the firmware of the Nextion HMI itself must also be updated (sometimes, for example, after certain updates to the editor) and this is only possible via the serial port.

Anyway, thanks for the support  :)
Ohm sweet Ohm | www.picbasic.nl

top204

I've performed this type of task a few times in the past, and there are a few ways of doing it. It all depends on the program's flow mechanisms.

The most efficient, and safest, way, is to create two interrupt buffers for both transmit and receive for both USARTs. Then nothing is missed because everything is received into a buffer array from either USART and immediately transmitted from them to the other USART, and the transmit is transmitted via the opposite USART etc...

Another way is to create a tight loop and whatever is received from USART1 is transmitted to USART2 and vice-versa. Within the loop, USART SFR flags are monitored to see what is receiving what, so it can be a loop that checks both USARTs.

Another way is to use a device that has PPS (Peripheral Pin Select). So the USART can change pins when required to talk to something else or listen from it. Then move back to its original pins.