View previous topic :: View next topic |
Author |
Message |
Manu59114
Joined: 22 Jan 2018 Posts: 34 Location: North of France
|
Fastest way to forward data from uart 1 to uart 2 |
Posted: Mon May 13, 2019 10:22 am |
|
|
Hello to all!
I was thinking that i need to transfer Data receive from UART1 and forward these data to the UART2 without modification...
What is the fastest way to do that and where is the best place to do that...
( inside the RDA interrupt like this?)
Code: |
#INT_RDA //RS232 RECEIVE DATA AVAILABLE - One CHAR is READY to be READ.
void RDA_isr(void)
{
int t;
buffer[next_in]=fgetc(PORT1); // get the data on port 1
fputc(buffer[next_int],PORT2); // send the data on port 2
t=next_in;
if(++next_in==BUFFER_SIZE)
{next_in=0;} // alors mettre 0 dans next_in pour revenir au début, ainsi
if(next_in==next_out) //
next_in=t; //
Compteur_Data_In++;
|
or it's better to use the transmit circular buffer too?
2/ Pic33 with DMA Channel?
is it better and quicker to use DMA channel to do that?
Thank you for your reply.
Wish you a great day!
Manu _________________ CCS + ICD3 + PIC18F46K80 |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Mon May 13, 2019 1:48 pm |
|
|
fastest ? ... use HW... a piece of wire
really
OK, if you want a 'controllable' SW solution, 2 choices.
1) Have the PIC control a reed switch connected between UART1 RCV and UART 2 XMT pins.
2) Use 2 ISRs, one for each UART, basically what you presented. How you code depends on other factors but using ISRs should be the fastest SW approach. I could get 1Mbaud having PC send to U1 which sent to U2 then to PC, using an 18F46K22. Test went overnight with zero problems.
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19505
|
|
Posted: Mon May 13, 2019 1:56 pm |
|
|
The speed is limited by the baud rate. Nothing else.
If you use DMA, it'll transfer the byte whenever the receive interrupt
triggers without using any processor time. _But_ the issue is that you won't
receive a 'transfer complete; interrupt until the specified number of bytes
for the DMA transfer has been moved. So if (for instance) you want to
process on a carriage return for example, you won't know this has
actually happened.
DMA is great if you have a fixed packet size, but otherwise can be awkward. |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
Re: Fastest way to forward data from uart 1 to uart 2 |
Posted: Mon May 13, 2019 2:02 pm |
|
|
Manu59114 wrote: | Hello to all!
I was thinking that i need to transfer Data receive from UART1 and forward these data to the UART2 without modification...
What is the fastest way to do that and where is the best place to do that...
( inside the RDA interrupt like this?)
Code: |
#INT_RDA //RS232 RECEIVE DATA AVAILABLE - One CHAR is READY to be READ.
void RDA_isr(void)
{
int t;
buffer[next_in]=fgetc(PORT1); // get the data on port 1
fputc(buffer[next_int],PORT2); // send the data on port 2
t=next_in;
if(++next_in==BUFFER_SIZE)
{next_in=0;} // alors mettre 0 dans next_in pour revenir au début, ainsi
if(next_in==next_out) //
next_in=t; //
Compteur_Data_In++;
|
or it's better to use the transmit circular buffer too?
2/ Pic33 with DMA Channel?
is it better and quicker to use DMA channel to do that?
Thank you for your reply.
Wish you a great day!
Manu |
If the only data ever transmitted to port 2 is the traffic received from port one and both ports are identically configured, then the solution you have listed is fine as it is. _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: Fastest way to forward data from uart 1 to uart 2 |
Posted: Mon May 13, 2019 4:00 pm |
|
|
Manu59114 wrote: |
What is the fastest way to do that and where is the best place to do that...
#INT_RDA
void RDA_isr(void)
{
int t;
buffer[next_in]=fgetc(PORT1); // get the data on port 1
fputc(buffer[next_int],PORT2); // send the data on port 2
|
You are doing two array accesses to send the byte. That's slow, compared to this:
Code: |
#int_rda
void RDA_isr(void)
{
int8 c;
int8 next_in;
c = fgetc(PORT1); // Get incoming byte in a char
fputc(c, PORT2); // Send the char back out
buffer[next_in] = c; // Then save it in the array
// Put the rest of #int_rda code here
}
|
Here's the .LST file:
Code: | .................... c = fgetc(PORT1);
000B6: BTFSS F9E.5
000B8: BRA 00B6
000BA: MOVFF FAE,59
.................... fputc(c, PORT2);
000BE: MOVF 59,W
000C0: RCALL 00AE
.................... buffer[next_in] = c;
000C2: CLRF 03
000C4: MOVF 5A,W
000C6: ADDLW 19
000C8: MOVWF FE9
000CA: MOVLW 00
000CC: ADDWFC 03,W
000CE: MOVWF FEA
000D0: MOVFF 59,FEF
|
The byte is quickly sent, and the costly array access is done after that. |
|
|
Manu59114
Joined: 22 Jan 2018 Posts: 34 Location: North of France
|
|
Posted: Wed May 15, 2019 2:18 am |
|
|
Thanks to all
Thank to Temtronic for the wire!!! why not the red relay but i can't add this on the existing PCB!
Thank to Ttelmah for the DMA explanation.
Thank to asmallri to confirm that my idea is not so bad!
Thank to PCM programmer for the code length demonstration
Wish you a great day
Manu _________________ CCS + ICD3 + PIC18F46K80 |
|
|
Manu59114
Joined: 22 Jan 2018 Posts: 34 Location: North of France
|
|
Posted: Wed May 15, 2019 2:34 am |
|
|
Thanks to all
Thank to Temtronic for the wire!!! why not the red relay but i can't add this on the existing PCB!
Thank to Ttelmah for the DMA explanation.
Thank to asmallri to confirm that my idea is not so bad!
Thank to PCM programmer for the code length demonstration
Wish you a great day
Manu _________________ CCS + ICD3 + PIC18F46K80 |
|
|
|