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

Problem when using 2 UART on PIC18F97J60

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



Joined: 25 Aug 2009
Posts: 175

View user's profile Send private message Yahoo Messenger

Problem when using 2 UART on PIC18F97J60
PostPosted: Mon Mar 19, 2012 10:12 pm     Reply with quote

Hi everyone !
I have a problem with RDA interrupt when using 2 UART (UART0 and UART2) on Pic 18F97J60.
My request is receive data on UART2 and send it through UART0.
I used Hyper Terminal to send data to Pic18 (UART2), and Pic18 send to PC (UART0) successed.
But when I connect between Pic18 and sensor, Pic18 send only ones string received from sensor and stop. If I reset Pic18, it send only ones string, too.
Please show me error in my problems.
Thanks all Smile

Code:

char user_str[11]="test,test,";
char gps_str[100]="";
char gps_str_send[80];
char gps_buffer[100]="";
int8 chk_gprs=0;
int8 index= 0;


#int_rda2
void ngat_gps(void)
{
   char c1;
   c1=fgetc(ID2);
 
   switch(c1)
   {
      case '$':   {
                  index=0;
                 
                  }
                  break;
                 
      case 13:    check_gprmc();
                  break;
      default:    {
                  gps_buffer[index]=c1;
                  index++;
                  }
                  break;
   }   
   
}

//------------------------------------------------------------------------------
void check_gprmc(void)
{
   if ((gps_buffer[1]=='G')&&(gps_buffer[2]=='P')&&(gps_buffer[3]=='R')&&(gps_buffer[4]=='M')&&(gps_buffer[5]=='C'))     
   {
      strcpy(gps_str,gps_buffer);
      fprintf(ID1,gps_str);
   }
   else {};
}


Config UART
Code:

#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,bits=8,stop=1,parity=n,stream=ID1) //GPRS_PORT
#use rs232(baud=4800, xmit=PIN_G1, rcv=PIN_G2,bits=8,stop=1,parity=n,stream=ID2) //GPS_PORT

_________________
Begin Begin Begin !!!
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Tue Mar 20, 2012 12:30 am     Reply with quote

The problem is caused by calling fprintf(ID1,), apparently the output to the other UART, from the interrupt service routine. It can be expected to cause at least an overflow of receive UART, blocking further reception.

If not using UART TX-interrupts, which would be the most effective solution, fprintf(ID1,) must be called in the main loop. You can e.g. use a flag (a so-called semaphore) to inform the main loop about new data to transmit.

A basically more flexible solution, not necessarily required in the present case, would receive the data to a circular buffer (using two index variables next_in and next_out) and perform also the processing of received data in the main loop. See EX_SISR.C as circular buffer implementation example.
dyeatman



Joined: 06 Sep 2003
Posts: 1924
Location: Norman, OK

View user's profile Send private message

PostPosted: Tue Mar 20, 2012 3:35 am     Reply with quote

They also need to add the ERRORS keyword to the RS232 setup lines.
_________________
Google and Forum Search are some of your best tools!!!!
tienchuan



Joined: 25 Aug 2009
Posts: 175

View user's profile Send private message Yahoo Messenger

PostPosted: Sat Mar 24, 2012 8:17 pm     Reply with quote

FvM wrote:
The problem is caused by calling fprintf(ID1,), apparently the output to the other UART, from the interrupt service routine. It can be expected to cause at least an overflow of receive UART, blocking further reception.

If not using UART TX-interrupts, which would be the most effective solution, fprintf(ID1,) must be called in the main loop. You can e.g. use a flag (a so-called semaphore) to inform the main loop about new data to transmit.

A basically more flexible solution, not necessarily required in the present case, would receive the data to a circular buffer (using two index variables next_in and next_out) and perform also the processing of received data in the main loop. See EX_SISR.C as circular buffer implementation example.


thanks for u answers.
I moved frintf() function go to main and it run well.
Thnks u very much.
Regards.
_________________
Begin Begin Begin !!!
tienchuan



Joined: 25 Aug 2009
Posts: 175

View user's profile Send private message Yahoo Messenger

PostPosted: Sat Mar 24, 2012 8:18 pm     Reply with quote

dyeatman wrote:
They also need to add the ERRORS keyword to the RS232 setup lines.

Thank for your answer.
Regards
_________________
Begin Begin Begin !!!
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