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

PIC24 does not generate interruption

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



Joined: 07 Sep 2003
Posts: 56

View user's profile Send private message

PIC24 does not generate interruption
PostPosted: Sat Mar 25, 2017 3:23 pm     Reply with quote

PIC24 does not generate uart1 interruption, when the function "envia_dtmf(10); " is called inside the main loop.

If I remove the function, it works.

Can anyone help?

Thanks

Orcino Borges


Code:

#include <24FJ128GB204.h>
#build (stack=256)

#FUSES HS                       //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOWDT                    //No Watch Dog Timer
#FUSES NOWINDIS                 //Watch Dog Timer in Window mode
#FUSES NOJTAG                   //JTAG disabled
#FUSES CKSFSM                   //Clock Switching is enabled, fail Safe clock monitor is enabled
#FUSES NOWDTCMX                 //WDT always uses LPRC as its clock source
#FUSES NOIESO                   //Internal External Switch Over mode disabled
#FUSES NOWPFP                   //Write/Erase Protect Page Start/End Location, set to page 0
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NODSBOR                  //BOR disabled in Deep Sleep
#FUSES NODSWDT                  //Deep Sleep Watchdog Timer disabled
#FUSES NODS                     //Deep Sleep operation is always disabled
#FUSES PLL6X                    //6x PLL Output Frequency is selected

#use delay(clock=60MHz,crystal=10MHz)


#use FIXED_IO( A_outputs=PIN_A10,PIN_A8,PIN_A7 )
#use FIXED_IO( B_outputs=PIN_B14,PIN_B13,PIN_B6 )
#use FIXED_IO( C_outputs=PIN_C5,PIN_C0 )

#define DATA_HT9200   PIN_A7
#define ON_OFF_GPRS   PIN_A8
#define CE_HT9200     PIN_A10
#define USB_DET       PIN_B3
#define STATUS_GPRS   PIN_B4
#define ON_RADIO      PIN_B6
#define PTT           PIN_B13
#define CLK_HT9200    PIN_B14
#define RST_GPS       PIN_C0
#define RST_BT        PIN_C5

//==============================================================================
//                                   Macros
//==============================================================================

#define ligaRadio    output_low(ON_RADIO);
#define desligaRadio output_high(ON_RADIO);

//=============================================================================
//
//=============================================================================

#pin_select U1TX=PIN_C1
#pin_select U1RX=PIN_C2
#use rs232(UART1, baud=9600,ERRORS,stream=GPS)

#pin_select U2TX=PIN_B7
#pin_select U2RX=PIN_B8
#use rs232(UART2, baud=9600, ERRORS,stream=BT)

#pin_select U3TX=PIN_C4
#pin_select U3RX=PIN_C3
#use rs232(UART3, baud=9600, ERRORS,stream=GPRS)

#pin_select INT1 = PIN_B9

#include <string.h>
#include <stdlib.h>
#include <GPS_read.c>

//#include <SIM900D.c>

//=============================================================================
//                             Funções
//=============================================================================

void envia_dtmf(unsigned int8 A);
void verificaDadosRxDTMF(void);
void enviaCoordenadas(void);

//=============================================================================
//                                Variaveis Globais
//=============================================================================

char GPSData[80];            // Buffer de recepção dos dados so GPS
char GPRSdata[128];
char BTdata[20];

unsigned int8 GPSDataPtr=0,
              BTDataPtr=0;

unsigned int8 GPSDataReady = FALSE,
              BTReady = FALSE;
             
unsigned int8 GPSmsgCount = 0;

char GPSrxCaracter;
char GPRSrxCaracter;
char BTrxCaracter;

unsigned int8  DTMFrx=0;
unsigned int8  rxDDC=0;
                           
int1 flagRxDTMF=0;
int1 A=0,B=0,C=0,D=0;

//==============================================================================
//                      Interrupção externa STD do HT9170
//==============================================================================

#INT_EXT1
void  ext0_isr_HT9170(void)
{
  flagRxDTMF=1;
 
  A = input(PIN_C9);
  B = input(PIN_C8);
  C = input(PIN_C7);
  D = input(PIN_C6);
}

//=============================================================================
//                            Interrupção RX UART1 GPS
// Recebe os dados do GPS  e armazena no buffer
//=============================================================================

#INT_RDA
void  rda_isr_GPS(void)
{
   GPSrxCaracter = fgetc(GPS);
   switch (GPSrxCaracter)
      {
      case '$':
         GPSDataPtr = 0;
      break;
     
      case '\n':
           {
             if( (GPSdata[3] == 'R') && (GPSdata[4] == 'M') && (GPSdata[5] == 'C') )
                  GPSDataReady = TRUE;
           }
          break;
      }
   
   GPSData[GPSDataPtr++ & 0x7F] = GPSrxCaracter;   
   
   if(GPSdataPtr > 79)
       GPSdataPtr=0;

}
//=============================================================================
//                     Interrupção RX UART2 BLUETOOTH
//=============================================================================

#INT_RDA2
void  rda2_isr_BT(void)
{
   
   BTrxCaracter = fgetc(BT);
   
   BTdata[BTDataPtr]=BTrxCaracter;
   
   if(BTrxCaracter == '\n')
        BTready = TRUE;
   
   BTDataPtr++;
   
   if(BTDataPtr > 20 )
        BTDataPtr=0;
}

//=============================================================================
//                       Interrupção RX UART3 GPRS
//=============================================================================

#INT_RDA3
void  rda3_isr_GPRS(void)
{
 
}

//=============================================================================
//                           Função principal
//=============================================================================

void main()
{

    setup_adc(ADC_OFF);
    setup_adc_ports(NO_ANALOGS, VSS_VDD);
    setup_timer1(TMR_DISABLED);
    setup_timer2(TMR_DISABLED);
    setup_timer3(TMR_DISABLED);
     
    enable_interrupts(INT_EXT1);
    enable_interrupts(INT_RDA);
    enable_interrupts(INT_RDA2);
    enable_interrupts(INT_RDA3);
    enable_interrupts(INTR_GLOBAL);
       
       
   while(TRUE)
   {     
      //envia_dtmf(10);
   
       
      if(flagRxDTMF)
          verificaDadosRxDTMF();
                 
      if (GPSDataReady)
          enviaCoordenadas(); 
         
    }
}

//=============================================================================
//                      Função que envia ton DTMF usando HT9200A
//=============================================================================

void envia_dtmf(unsigned int8 A)
{
   int8 k;
 
   output_high(CE_HT9200);
   output_low(CLK_HT9200);
   output_high(CLK_HT9200);
   output_low(CE_HT9200);
   delay_ms(15);

    A = A & 0B00001111;

    if (A == 0)   // 0 em DTMF =10
         A = 10;

for(k=0;k<5;k++)
      {
        if(bit_test(A,k) == 1)
           output_high(DATA_HT9200); 
                   
        else
           output_low(DATA_HT9200);
         
       
         output_low(CLK_HT9200);
         delay_ms(1);
         output_high(CLK_HT9200);
         delay_ms(1);
       }

 output_high(DATA_HT9200);  // DATA_HT9200=1;

 delay_ms(100); // VALOR MINIMO DE DURAÇÃO DE CADA TOM DTMF

 for(k=0;k<5;k++)
      {
      output_low(CLK_HT9200);
      delay_ms(1);
      output_high(CLK_HT9200);
      delay_ms(1);
      }

delay_ms(50);

}

//=============================================================================
//
//=============================================================================

void verificaDadosRxDTMF(void)
 {   
  if(A==1)  bit_set(DTMFrx,0);
  if(B==1)  bit_set(DTMFrx,1);
  if(C==1)  bit_set(DTMFrx,2);
  if(D==1)  bit_set(DTMFrx,3);
 }

//==============================================================================
//
//==============================================================================
 void enviaCoordenadas(void)
      {
       
          GPRMCInfo MyGPRMCInfo; 
         
          GPRMC_decode(GPSData, &MyGPRMCInfo);
          if (MyGPRMCInfo.Valid == 'A')
              {
              delay_ms(500);
              fprintf(BT,"\n\rTime: %d:%d:%d\n\r",MyGPRMCInfo.DT.Hour,   MyGPRMCInfo.DT.Minute, MyGPRMCInfo.DT.Second);
              fprintf(BT,"Date: %d/%d/%d\n\r",    MyGPRMCInfo.DT.Day,    MyGPRMCInfo.DT.Month, MyGPRMCInfo.DT.Year);
              fprintf(BT,"Latitude: %f %c\n\r",   MyGPRMCInfo.Latitude,  MyGPRMCInfo.N_S);
              fprintf(BT,"Longitude: %f %c\n\r",  MyGPRMCInfo.Longitude, MyGPRMCInfo.E_W);
              fprintf(BT,"Speed: %f knots\n\r",   MyGPRMCInfo.Speed);           
              }
         
         else
            fprintf(BT,"Detectando satelites...\n\r"); 
       
          GPSDataReady = FALSE;
       
     }
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Mar 25, 2017 5:21 pm     Reply with quote

Correct the simple things first. Here you have the #int_rda3 routine,
and you have enabled it in main(), but you don't get the character.
You have an empty routine. If a character comes in, this will just keep
interrupting over and over again, and your program will appear to lock
up. Never do this. Add an fgetc() statement to read the character.
Quote:
#INT_RDA3
void rda3_isr_GPRS(void)
{

}


2nd thing. At least for your initial testing, get rid of this stuff below.
For most people, "fixed_io" causes trouble. It doesn't help.
Quote:
#use FIXED_IO( A_outputs=PIN_A10,PIN_A8,PIN_A7 )
#use FIXED_IO( B_outputs=PIN_B14,PIN_B13,PIN_B6 )
#use FIXED_IO( C_outputs=PIN_C5,PIN_C0 )
Orcino



Joined: 07 Sep 2003
Posts: 56

View user's profile Send private message

PostPosted: Sun Mar 26, 2017 12:38 pm     Reply with quote

I did the changes you said, but it did not work.

I checked that this problem only happens, when there is some command like output_high or output_low.

If I remove these commands from the function, the program works.

Any idea what might be going on?

Thank you

Orcino

Code:


#include <24FJ128GB204.h>
#build (stack=256)

#FUSES HS                       //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOWDT                    //No Watch Dog Timer
#FUSES NOWINDIS                 //Watch Dog Timer in Window mode
#FUSES NOJTAG                   //JTAG disabled
#FUSES CKSFSM                   //Clock Switching is enabled, fail Safe clock monitor is enabled
#FUSES NOWDTCMX                 //WDT always uses LPRC as its clock source
#FUSES NOIESO                   //Internal External Switch Over mode disabled
#FUSES NOWPFP                   //Write/Erase Protect Page Start/End Location, set to page 0
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NODSBOR                  //BOR disabled in Deep Sleep
#FUSES NODSWDT                  //Deep Sleep Watchdog Timer disabled
#FUSES NODS                     //Deep Sleep operation is always disabled
#FUSES PLL6X                    //6x PLL Output Frequency is selected

#use delay(clock=60MHz,crystal=10MHz)

// #use FIXED_IO( A_outputs=PIN_A10,PIN_A8,PIN_A7 )
// #use FIXED_IO( B_outputs=PIN_B14,PIN_B13,PIN_B6 )
// #use FIXED_IO( C_outputs=PIN_C5,PIN_C0 )

#use standard_io(A)
#use standard_io(B)
#use standard_io(C)

#define DATA_HT9200   PIN_A7
#define ON_OFF_GPRS   PIN_A8
#define CE_HT9200     PIN_A10
#define USB_DET       PIN_B3
#define STATUS_GPRS   PIN_B4
#define ON_RADIO      PIN_B6
#define PTT           PIN_B13
#define CLK_HT9200    PIN_B14
#define RST_GPS       PIN_C0
#define RST_BT        PIN_C5

//==============================================================================
//                                   Macros
//==============================================================================

#define ligaRadio    output_low(ON_RADIO);
#define desligaRadio output_high(ON_RADIO);

//=============================================================================
//
//=============================================================================

#pin_select U1TX=PIN_C1
#pin_select U1RX=PIN_C2
#use rs232(UART1, baud=9600,ERRORS,stream=GPS)

#pin_select U2TX=PIN_B7
#pin_select U2RX=PIN_B8
#use rs232(UART2, baud=9600, ERRORS,stream=BT)

#pin_select U3TX=PIN_C4
#pin_select U3RX=PIN_C3
#use rs232(UART3, baud=9600, ERRORS,stream=GPRS)

#pin_select INT1 = PIN_B9

#include <string.h>
#include <stdlib.h>
#include <GPS_read.c>

//#include <SIM900D.c>

//=============================================================================
//                             Funções
//=============================================================================

void envia_dtmf(unsigned int8 A);
void verificaDadosRxDTMF(void);
void enviaCoordenadas(void);

//=============================================================================
//                                Variaveis Globais
//=============================================================================

char GPSData[80];            // Buffer de recepção dos dados so GPS
char GPRSdata[128];
char BTdata[20];

unsigned int8 GPSDataPtr=0,
              BTDataPtr=0;

unsigned int8 GPSDataReady = FALSE,
              BTReady = FALSE;
             
unsigned int8 GPSmsgCount = 0;

char GPSrxCaracter;
char GPRSrxCaracter;
char BTrxCaracter;

unsigned int8  DTMFrx=0;
unsigned int8  rxDDC=0;
                           
int1 flagRxDTMF=0;
int1 A=0,B=0,C=0,D=0;

//==============================================================================
//                      Interrupção externa STD do HT9170
//==============================================================================

#INT_EXT1
void  ext0_isr_HT9170(void)
{
  flagRxDTMF=1;
 
  A = input(PIN_C9);
  B = input(PIN_C8);
  C = input(PIN_C7);
  D = input(PIN_C6);
}

//=============================================================================
//                            Interrupção RX UART1 GPS
// Recebe os dados do GPS  e armazena no buffer
//=============================================================================

#INT_RDA
void  rda_isr_GPS(void)
{
   GPSrxCaracter = fgetc(GPS);
       
   switch (GPSrxCaracter)
      {
      case '$':
         GPSDataPtr = 0;
      break;
     
      case '\n':
           {
            if( (GPSdata[3] == 'R') && (GPSdata[4] == 'M') && (GPSdata[5] == 'C') )
                  GPSDataReady = TRUE;
           }
          break;
      }
   
   GPSData[GPSDataPtr++ & 0x7F] = GPSrxCaracter;   
   
   if(GPSdataPtr > 79)
       GPSdataPtr=0;

}
//=============================================================================
//                     Interrupção RX UART2 BLUETOOTH
//=============================================================================

#INT_RDA2
void  rda2_isr_BT(void)
{
   
   BTrxCaracter = fgetc(BT);
   
   BTdata[BTDataPtr]=BTrxCaracter;
   
   if(BTrxCaracter == '\n')
        BTready = TRUE;
   
   BTDataPtr++;
   
   if(BTDataPtr > 20 )
        BTDataPtr=0;
}

//=============================================================================
//                       Interrupção RX UART3 GPRS
//=============================================================================

#INT_RDA3
void  rda3_isr_GPRS(void)
{
GPRSrxCaracter = fgetc(GPRS);
}

//=============================================================================
//                           Função principal
//=============================================================================

void main()
{

    setup_adc(ADC_OFF);
    setup_adc_ports(NO_ANALOGS, VSS_VDD);
    setup_timer1(TMR_DISABLED);
    setup_timer2(TMR_DISABLED);
    setup_timer3(TMR_DISABLED);
     
    enable_interrupts(INT_EXT1);
    enable_interrupts(INT_RDA);
    enable_interrupts(INT_RDA2);
    enable_interrupts(INT_RDA3);
    enable_interrupts(INTR_GLOBAL);
       
       
   while(1)
   {     
   
      envia_dtmf(10);
     
      if(flagRxDTMF)
          verificaDadosRxDTMF();
                 
      if (GPSDataReady)
          enviaCoordenadas(); 
         
    }
}

//=============================================================================
//                      Função que envia ton DTMF usando HT9200A
//=============================================================================

void envia_dtmf(unsigned int8 A)
{
   int8 k;
 
   output_high(CE_HT9200);
   output_low(CLK_HT9200);
   output_high(CLK_HT9200);
   output_low(CE_HT9200);
   delay_ms(15);

 
   A = A & 0B00001111;

    if (A == 0)   // 0 em DTMF =10
         A = 10;

for(k=0;k<5;k++)
      {
        if(bit_test(A,k) == 1)
           output_high(DATA_HT9200); 
                   
        else
           output_low(DATA_HT9200);
         
       
         output_low(CLK_HT9200);
         delay_ms(1);
         output_high(CLK_HT9200);
         delay_ms(1);
       }

 output_high(DATA_HT9200);  // DATA_HT9200=1;

 delay_ms(100); // VALOR MINIMO DE DURAÇÃO DE CADA TOM DTMF

 for(k=0;k<5;k++)
      {
      output_low(CLK_HT9200);
      delay_ms(1);
      output_high(CLK_HT9200);
      delay_ms(1);
      }

delay_ms(50);

}

//=============================================================================
//
//=============================================================================

void verificaDadosRxDTMF(void)
 {   
  if(A==1)  bit_set(DTMFrx,0);
  if(B==1)  bit_set(DTMFrx,1);
  if(C==1)  bit_set(DTMFrx,2);
  if(D==1)  bit_set(DTMFrx,3);
 }

//==============================================================================
//
//==============================================================================
 void enviaCoordenadas(void)
      {
       
          GPRMCInfo MyGPRMCInfo; 
         
          GPRMC_decode(GPSData, &MyGPRMCInfo);
          if (MyGPRMCInfo.Valid == 'A')
              {
              delay_ms(500);
              fprintf(BT,"\n\rTime: %d:%d:%d\n\r",MyGPRMCInfo.DT.Hour,   MyGPRMCInfo.DT.Minute, MyGPRMCInfo.DT.Second);
              fprintf(BT,"Date: %d/%d/%d\n\r",    MyGPRMCInfo.DT.Day,    MyGPRMCInfo.DT.Month, MyGPRMCInfo.DT.Year);
              fprintf(BT,"Latitude: %f %c\n\r",   MyGPRMCInfo.Latitude,  MyGPRMCInfo.N_S);
              fprintf(BT,"Longitude: %f %c\n\r",  MyGPRMCInfo.Longitude, MyGPRMCInfo.E_W);
              fprintf(BT,"Speed: %f knots\n\r",   MyGPRMCInfo.Speed);           
              }
         
         else
            fprintf(BT,"Detectando satelites...\n\r"); 
       
          GPSDataReady = FALSE;
       
     }
Ttelmah



Joined: 11 Mar 2010
Posts: 19550

View user's profile Send private message

PostPosted: Sun Mar 26, 2017 12:59 pm     Reply with quote

You need to learn to debug.
Test one thing at a time.

Your problem is your code to drive the HT9200A, is really badly flawed.
You end with the chip left enabled. You have a huge delay (150mSec - that's 150 characters at your serial rate - no wonder the serial stops working...).
The chip accepts it's data at 100KHz. You don't need/want the huge delays.
The whole code is wrong. You need to drop CE, send five bits, and raise CE.
If you want to delay leaving the tone on, then have a tick timer, and keep in your main loop, and send the off code when this expires.
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