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 CCS Technical Support

24F16KA102 / UART Interrupts

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



Joined: 18 Mar 2011
Posts: 2

View user's profile Send private message

24F16KA102 / UART Interrupts
PostPosted: Sun Mar 20, 2011 11:04 am     Reply with quote

I am having a problem with UART interrupts on the 24F16KA102. My UART ISR is never called when I type in HyperTerminal. When I poll for chars in main() with getc(), I receive the chars.

This is obviously a basic need that is done all the time, so I must be doing something stupid. Could someone review my code below?

Thanks.

I found the example code, EX_SISR.C and stripped it down to show the problem.

Setup :
24F16KA102
XLP 16-Bit Development board.
Code:

#include <24F16KA102.h>
#fuses HS, NOWDT, NOPROTECT
#use delay(clock=8000000)
#USE rs232(BAUD=57600, XMIT=PIN_B0, RCV=PIN_B1)


#define BUFFER_SIZE 32
BYTE buffer[BUFFER_SIZE];
BYTE next_in = 0;
BYTE next_out = 0;


#int_rda
void serial_isr() {
   int t;

   buffer[next_in]=getc();
   t=next_in;
   next_in=(next_in+1) % BUFFER_SIZE;
   if(next_in==next_out)
     next_in=t;           // Buffer full !!
}

#define bkbhit (next_in!=next_out)

BYTE bgetc() {
   BYTE c;

   while(!bkbhit) ;
   c=buffer[next_out];
   next_out=(next_out+1) % BUFFER_SIZE;
   return(c);
}

void main()
{
   setup_oscillator( OSC_INTERNAL, 8000000);

   enable_interrupts(int_rda);
   enable_interrupts(intr_global);

   printf("\r\n\Running...\r\n");

               // The program will delay for 10 seconds and then display
               // any data that came in during the 10 second delay

   do {
      delay_ms(4000);
      printf("\r\nBuffered data => ");
      while(bkbhit)
        putc( bgetc() );
   } while (TRUE);
}
temtronic



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

View user's profile Send private message

PostPosted: Sun Mar 20, 2011 1:23 pm     Reply with quote

I think the ISR only works with the hardware UART that being said are your pin assignments in the RS232 () directive correct for hardware UART ?
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sun Mar 20, 2011 11:46 pm     Reply with quote

RB0 and RB1 are hardware UART pins, but of UART2 that is automatically selected by your #use RS232 statement. So INT_RDA2 has to be used.
mwalter



Joined: 18 Mar 2011
Posts: 2

View user's profile Send private message

PostPosted: Mon Mar 21, 2011 7:22 am     Reply with quote

That did it.

Thanks for the help.
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