|
|
View previous topic :: View next topic |
Author |
Message |
umka
Joined: 28 Aug 2007 Posts: 99 Location: New Zealand
|
Stream and Interrupts |
Posted: Sun Apr 20, 2008 10:46 pm |
|
|
I am wanting to use two serial communication ports on a PIC16F877a so have set it up as follows.
Code: | #include <16F877a.H>
#device icd=true
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
#use rs232(baud = 19200, xmit=PIN_C6, rcv = PIN_C7, ERRORS, stream = PC)
#use rs232(baud = 19200, xmit=PIN_C4, rcv = PIN_C5, ERRORS, stream = Slave_Micro)
int8 i, value, stage;
int8 Serial_Array[6];
#INT_RDA
void serial_isr()
{
i = 0;
for(i = 0; i < 5; i++) // if Set i upper limit to Serial_Array_Size() then will
{ //exit as soon as full and do not need return
value = getc(PC);
Serial_Array[i] = value;
}
Stage = 1;
}
void main()
{
clear_interrupt(INT_RDA);
enable_interrupts(int_rda);
enable_interrupts(GLOBAL);
the code carries on here |
Now the problem is the #INT_RDA cant tell between the two streams i have set up for comms (PC and Slave micro) and i need it to save the the array in "serial array" for the one from the pc and "slave array" for the one from the slave micro.
I need an interrupt function like #int_rda(PC) and #int_rda(Slave_micro) but i cant figure out how to do this.
. |
|
|
andrewg
Joined: 17 Aug 2005 Posts: 316 Location: Perth, Western Australia
|
|
Posted: Mon Apr 21, 2008 1:01 am |
|
|
Only the hardware UART generates interrupts. Your "PC" stream is on the hardware UART, while the "Slave_Micro" stream is on a software UART.
I've never used a software UART, but I imagine you'd leave the hardware one to look after itself via interrupts, while your mainline sits and waits on data from the software UART.
If your PIC has to be doing other things at the same time handling both serial streams, then I'm pretty sure that's not going to work. Reliably anyway. If you can arrange things so that your slave only speaks when spoken to, then that should work OK.
Alternatively, two hardware UARTs are an option. Some PICs have two, and you can get SPI/I2C/etc UARTs as well. _________________ Andrew |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
|
|
|
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
|