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

Interrupt problems 24F16KA102

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



Joined: 13 Apr 2011
Posts: 2

View user's profile Send private message

Interrupt problems 24F16KA102
PostPosted: Wed Apr 13, 2011 12:49 pm     Reply with quote

Hello Folks,

I seem to be having a problem getting an interrupt to fire when serial data is available on UART2 of my PIC processor. I'm sure my hardware is good, and serial data has been verified with a scope on the UART input pin. Attached is my code. It's a modified sample I found here on the BBS. Any help or suggestions would be greatly appreciated. Using PCD 4.114.

Thanks,
Shawn
Code:

#include "C:\Users\Public\Documents\main4.h"
#include "string.h"
#include "stdio.h"

enum RECEIVE_STATES  {IDLE, RECEIVING};
enum RECEIVE_STATES receive_state = IDLE;
#INT_RDA2
#define STX           0x31
#define LINEFEED      0x0A
#define MAX_STR_LEN   40

char RxBuff[MAX_STR_LEN + 1];           // +1 for terminating zero.
int8 rxBuffPtr = 0;

int8 new_string_received = FALSE;
char StringBuffer[MAX_STR_LEN + 1];     // +1 for terminating zero.


 

#use rs232( baud=1200, UART2, parity=N, bits=8)




// Compare the new received string to the previous string.
// If a new string is found than the string is copied for comparison next time.
void CheckForNewString()
{
  if (strcmp(RxBuff, StringBuffer) != 0)
  {
    // New string found, copy the string and set flag.
    strcpy(StringBuffer, RxBuff);
    new_string_received = TRUE;
  }
}   

#int_RDA2
void  RDA2_isr(void)
{
char data_in;
   
   
output_low(PIN_B15); //flash LED to know that the interrupt got triggered
delay_ms(700);
output_high(PIN_B15); //flash LED to know that the interrupt got triggered

   
  data_in = getc();                // Get character from rs232
  putc( data_in );                 // Echo character to PC2


  switch (receive_state)
  {
    case IDLE:
      if (data_in == STX)
        receive_state = RECEIVING;
      break;
    case RECEIVING:
      if (data_in == LINEFEED)    // End of string terminator found?
      {
        RxBuff[rxBuffPtr] = '\0';     // Terminate string
        CheckForNewString();
        receive_state = IDLE;
        rxBuffPtr = 0;
      }
      else
      {
        // Only process readable characters
        if ((data_in >= 0x20) && (data_in < 127))
        {
          if (RxBuffPtr < MAX_STR_LEN)
          {
            RxBuff[rxBuffPtr] = data_in;
            rxBuffPtr++;
          }
        }
      }
      break;
  }
}

void main()
{
 setup_spi( FALSE );

setup_adc_ports(sAN12);
setup_adc(ADC_OFF | ADC_TAD_MUL_0);
setup_wdt(WDT_ON);
setup_timer1(TMR_DISABLED|TMR_DIV_BY_1);
enable_interrupts(int_rda2);
   
StringBuffer[0] = 0;  // Terminate string.
 
       

  while (1)
  {
   
    if (new_string_received == TRUE)
      printf("New string found: %s\n", StringBuffer);
  }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Apr 13, 2011 1:12 pm     Reply with quote

I don't see where you ever enable global interrupts in your code.
Example, near the start of main():
http://www.ccsinfo.com/forum/viewtopic.php?t=45004&highlight=intr_global+enable_interrupts
shawnperkins



Joined: 13 Apr 2011
Posts: 2

View user's profile Send private message

PostPosted: Wed Apr 13, 2011 1:26 pm     Reply with quote

That did it. I was trying to put 'enable_interrupts(GLOBAL)' in my code, but it was throwing an error, 'Unidentified identifier GLOBAL'. By placing 'enable_interrupts(intr_global)' fixed the problem. Thanks for the fast reply!

Shawn
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