Jump to content
Sign in to follow this  
HOEK

Dual USART PIC16F877A

Recommended Posts

Hi all.  

 

I'm trying to use both the 877's hardware USART as well as a software USART generated by the C2C compiler in order to communicate with two serial devices.  I'm able to transmit from both USARTs.  

 

How can I distinguish between a hardware USART Rx interrupt and the software USART Rx interrupt?  I can catch the hardware interrupt, but not the Software one.

 

Thanks in advance

Share this post


Link to post
Share on other sites

Here is a code snippet showing the configuration and the Interrupt Service Routine:

 

/*--------------------------------------------------------------------*

 Configuration

*--------------------------------------------------------------------*/

#pragma CLOCK_FREQ 4000000

#include

#define test_bit(x,y) (x&(1<

 

//Additional RS232

#pragma RS232_TXPORT PORTA

#pragma RS232_TXPIN 3 //4 on 877

#pragma RS232_RXPORT PORTA

#pragma RS232_RXPIN 2 //3 on 877

#pragma RS232_BAUD 9600

#pragma TRUE_RS232 1

 

/*--------------------------------------------------------------------*

 Interrupt Service Routine

*--------------------------------------------------------------------*/

void interrupt(void)

{

RxFlag = SWPORTA; // Test PORTA status

 

   if ( test_bit(pir1, RCIF) )

{    

       if( test_bit(rcsta, FERR) || test_bit(rcsta, OERR) )

{

           clear_bit(rcsta,CREN);

           nop();  

           set_bit(rcsta,CREN);

       }

       else if ( RxFlag != 0 )   //Just messing without success...

       {

RxByte = rcreg;

handleSwUsartChar(RxByte);

       }

       handleReceivedChar(rcreg);

}

}

Share this post


Link to post
Share on other sites

The software uart routines don't generate interrupts, because they're foreground processes. If you getchar() or putchar() your code has to wait for these operations to complete.

 

Look at the .asm file generated by the C compiler and you'll see what I mean.

 

HTH

 

bb

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...