CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Fastest way to forward data from uart 1 to uart 2

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Manu59114



Joined: 22 Jan 2018
Posts: 34
Location: North of France

View user's profile Send private message

Fastest way to forward data from uart 1 to uart 2
PostPosted: Mon May 13, 2019 10:22 am     Reply with quote

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: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon May 13, 2019 1:48 pm     Reply with quote

fastest ? ... use HW... a piece of wire Very Happy

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: 19195

View user's profile Send private message

PostPosted: Mon May 13, 2019 1:56 pm     Reply with quote

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: 1630
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

Re: Fastest way to forward data from uart 1 to uart 2
PostPosted: Mon May 13, 2019 2:02 pm     Reply with quote

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

View user's profile Send private message

Re: Fastest way to forward data from uart 1 to uart 2
PostPosted: Mon May 13, 2019 4:00 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed May 15, 2019 2:18 am     Reply with quote

Thanks to all

Thank to Temtronic for the wire!!! why not the red relay but i can't add this on the existing PCB! Wink

Thank to Ttelmah for the DMA explanation. Wink

Thank to asmallri to confirm that my idea is not so bad! Wink

Thank to PCM programmer for the code length demonstration Wink

Wish you a great day

Manu
_________________
CCS + ICD3 + PIC18F46K80
Manu59114



Joined: 22 Jan 2018
Posts: 34
Location: North of France

View user's profile Send private message

PostPosted: Wed May 15, 2019 2:34 am     Reply with quote

Thanks to all

Thank to Temtronic for the wire!!! why not the red relay but i can't add this on the existing PCB! Wink

Thank to Ttelmah for the DMA explanation. Wink

Thank to asmallri to confirm that my idea is not so bad! Wink

Thank to PCM programmer for the code length demonstration Wink

Wish you a great day

Manu
_________________
CCS + ICD3 + PIC18F46K80
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group