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

Stream and Interrupts

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



Joined: 28 Aug 2007
Posts: 99
Location: New Zealand

View user's profile Send private message

Stream and Interrupts
PostPosted: Sun Apr 20, 2008 10:46 pm     Reply with quote

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

View user's profile Send private message Visit poster's website

PostPosted: Mon Apr 21, 2008 1:01 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Apr 21, 2008 5:58 am     Reply with quote

A software UART is an option but it means a high MCU overhead doing the needed polling.
A better solution is to implement an interrupt driven software UART. I redirect you to some
of the previous threads where we had discussed this issues.

http://www.ccsinfo.com/forum/viewtopic.php?t=25564&highlight=stream
http://www.ccsinfo.com/forum/viewtopic.php?t=26808&highlight=stream

Humberto
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