View previous topic :: View next topic |
Author |
Message |
ksraja
Joined: 08 Dec 2014 Posts: 8
|
2 uart interrupt code |
Posted: Sat Dec 27, 2014 5:31 am |
|
|
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: 9229 Location: Greensville,Ontario
|
|
Posted: Sat Dec 27, 2014 7:02 am |
|
|
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
|
|
Posted: Sat Dec 27, 2014 8:09 am |
|
|
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
|
|
Posted: Sat Dec 27, 2014 8:23 am |
|
|
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
|
|
Posted: Sat Dec 27, 2014 8:27 am |
|
|
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
|
|
Posted: Sat Dec 27, 2014 8:30 am |
|
|
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
|
|
Posted: Mon Dec 29, 2014 10:16 pm |
|
|
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. |
|
|
|