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

serial interrupt on PIC16F1574 not working

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



Joined: 01 Apr 2007
Posts: 192

View user's profile Send private message

serial interrupt on PIC16F1574 not working
PostPosted: Thu Feb 25, 2021 11:43 am     Reply with quote

Windows 10
PCWHD V5.071

I'm trying to get the serial interrupt service routine to work on a PIC16F1574 but there's not response. I use this same method with the PIC12LF1572 and it works fine. I've used this same method with multiple other chips and it works fine for them, too. Just not the PIC16F1574.

Code:

#include <16F1574.h>
#device adc=10
#fuses NODEBUG       // No Debug mode for ICD
#fuses NOWDT
#fuses INTRC_IO      // internal RC osc with no clkout
#fuses NOPROTECT
#fuses MCLR
#fuses PUT
#fuses NOBROWNOUT

#use delay(internal=16M)
#use rs232(baud=38400, parity=N, xmit=PIN_C4, rcv=PIN_C5, bits=8)
#define PA_DEF 0b11111111
#define PA_TRIS 0b11001111
#define PC_DEF 0b11111111
#define PC_TRIS 0b11100111

int1 sFlag;       // serial input char seen
char sCh;         // serial character received

// ---- serial port input ISR ----
#int_RDA
void serialISR(void)
{
   sCh = getc();
   sFlag = TRUE;            // command ready for background execution
}

void main(void)
{
   set_tris_a(PA_TRIS);
   set_tris_c(PC_TRIS);
   set_rtcc(0);
   setup_timer_0(RTCC_INTERNAL | RTCC_DIV_256);
   output_a(PA_DEF);
   output_c(PC_DEF);
   sFlag = FALSE;
   
   clear_interrupt(INT_RDA);
   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);
   delay_ms(500);
   
   printf("startup\r\n");
   while(TRUE)
   {
      if(sFlag) // if serial input seen
      {
         printf("character %c was seen\r\n", sCh);
         sFlag = FALSE;
      }
   }
}


Is there something special about the serial port with this specific chip?

Thanks.
Ttelmah



Joined: 11 Mar 2010
Posts: 17398

View user's profile Send private message

PostPosted: Thu Feb 25, 2021 1:18 pm     Reply with quote

You need to set it up with PPS.

On any chip where the serial pins support PPS, the way to set it up
is to use #PIN_SELECT, and refer directly to the UART number in #USE
RS232.
Look at the sticky at the top of the forum showing how to do this.

Unless you do this, the default is to implement a software UART, which then
implies no INT_RDA.... Sad
temtronic



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

View user's profile Send private message

PostPosted: Thu Feb 25, 2021 1:29 pm     Reply with quote

also...
You should add 'ERRORS' as an option to this line...

#use rs232(baud=38400, parity=N, xmit=PIN_C4, rcv=PIN_C5, bits=8)

It will prevent the PICs HW UART from 'locking up' when more than 2-3 characters are sent to it.
Jay
starfire151



Joined: 01 Apr 2007
Posts: 192

View user's profile Send private message

PostPosted: Thu Feb 25, 2021 2:27 pm     Reply with quote

Thanks very much!

My oversight... Embarassed Works like a charm!
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