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 CCS Technical Support

2 uart interrupt code

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



Joined: 08 Dec 2014
Posts: 8

View user's profile Send private message

2 uart interrupt code
PostPosted: Sat Dec 27, 2014 5:31 am     Reply with quote

Hi

I am using PIC18F6722, in this controller have 2 uart. I want to use both uart interrupt, but the controller is not working.
Code:

#use rs232(baud=115200,xmit=PIN_C6,rcv=PIN_C7,ERRORS)
#use rs232(baud=9600,xmit=PIN_G1,rcv=PIN_G2,parity=N,ERRORS)

#INT_RDA
void serial_reciv_int(void)
{
   byte rda_cnt;   
   int_rdacount=0;   
   
   for(rda_cnt=0;rda_cnt<=2;rda_cnt++)
   {
      rxchar = getc();
      rxdata[rda_cnt]=rxchar;
   }

      int_rdacount=rxdata[2];

   for(rda_cnt=0;rda_cnt<=int_rdacount-1;rda_cnt++)
   {
      rxchar = getc();
      rxdata[rda_cnt]=rxchar;
   }
receivedrx=1;
   
}

#INT_RDA2
void serial_reciv_int1(void)
{
   byte rda_cnt;   
   int_rdacount=0;   
   
   for(rda_cnt=0;rda_cnt<=2;rda_cnt++)
   {
      rxchar = getc();
      rxdata[rda_cnt]=rxchar;
   }

      int_rdacount=rxdata[2];

   for(rda_cnt=0;rda_cnt<=int_rdacount-1;rda_cnt++)
   {
      rxchar = getc();
      rxdata[rda_cnt]=rxchar;
   }
receivedrx=1;
   
}
temtronic



Joined: 01 Jul 2010
Posts: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Dec 27, 2014 7:02 am     Reply with quote

You need to use buffers. Have a look at the CCS example ex_sisr.c. See how they do it,try with one UART, then copy it for the 2nd UART. It does work for 2 UARTs both running at 115k200.


jay
dyeatman



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

View user's profile Send private message

PostPosted: Sat Dec 27, 2014 8:09 am     Reply with quote

You must first understand that an interrupt means only ONE character is
available and you should getc() only ONE character then get out of the
ISR ASAP similar to this:

Code:
#INT_RDA
void serial_reciv_int(void)
{
      rxdata1[rda_cnt1++] = getc();
      // manage your buffer pointer here
   
}


Then you need to manage the character buffer pointer (RDA_CNT1).
As Temtronic says, you need to look at ex_sisr.c which shows you how to do this.
BTW, you will need two separate character buffers (rxdata1 and rxdata2), one for each interrupt.
You also have to enable both interrupts INT_RDA and INT_RDA2
_________________
Google and Forum Search are some of your best tools!!!!
ksraja



Joined: 08 Dec 2014
Posts: 8

View user's profile Send private message

PostPosted: Sat Dec 27, 2014 8:23 am     Reply with quote

temtronic wrote:
You need to use buffers. Have a look at the CCS example ex_sisr.c. See how they do it,try with one UART, then copy it for the 2nd UART. It does work for 2 UARTs both running at 115k200.


jay




can you send any sample code
ksraja



Joined: 08 Dec 2014
Posts: 8

View user's profile Send private message

PostPosted: Sat Dec 27, 2014 8:27 am     Reply with quote

dyeatman wrote:
You must first understand that an interrupt means only ONE character is
available and you should getc() only ONE character then get out of the
ISR ASAP similar to this:

Code:
#INT_RDA
void serial_reciv_int(void)
{
      rxdata1[rda_cnt1++] = getc();
      // manage your buffer pointer here
   
}


Then you need to manage the character buffer pointer (RDA_CNT1).
As Temtronic says, you need to look at ex_sisr.c which shows you how to do this.
BTW, you will need two separate character buffers (rxdata1 and rxdata2), one for each interrupt.
You also have to enable both interrupts INT_RDA and INT_RDA2







thanks.... but i want to use both interrupt with same array
dyeatman



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

View user's profile Send private message

PostPosted: Sat Dec 27, 2014 8:30 am     Reply with quote

Don't need to, if you have the CCS compiler you already have it in the examples directory.
As was said earlier, look at the examples already provided.
Also, search this forum for sisr.c to find usage examples.

You want to put the characters from both interrupts into the same buffer?
You can do this but you won't know where they came from...
You can use a multidimensional array I suppose but that will be hard to follow.
_________________
Google and Forum Search are some of your best tools!!!!
ksraja



Joined: 08 Dec 2014
Posts: 8

View user's profile Send private message

PostPosted: Mon Dec 29, 2014 10:16 pm     Reply with quote

dyeatman wrote:
Don't need to, if you have the CCS compiler you already have it in the examples directory.
As was said earlier, look at the examples already provided.
Also, search this forum for sisr.c to find usage examples.

You want to put the characters from both interrupts into the same buffer?
You can do this but you won't know where they came from...
You can use a multidimensional array I suppose but that will be hard to follow.



Thank you, now my code is working fine.
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