I can't receive interrupt on RA2 16F(L)18346 SOLVED

General discussion on mikroC PRO for PIC.
Post Reply
Author
Message
leo73
Posts: 252
Joined: 09 Jan 2014 15:45

I can't receive interrupt on RA2 16F(L)18346 SOLVED

#1 Post by leo73 » 15 Nov 2022 16:01

Hello to every one,
I can''t receive interrupt signal on my mcu by infrared sensor IR attached on RA2(int).
Probabily or i forgot to set some part of INTCON register, or part of interrupt code is wrong and not use RA2 as interrupt !!!

On the datasheet there's wrote that RA2 is default Interrupt pin, so probabily remappable Interrupt is not required !!
Below interrupt code and in attachement there's full code and a little part of mcu datasheet.
Thank you for your Help.

PS: actually I'm using an IR Transmitter remote control In program if this signal is received send me a simply message on UART. (next step will be build a real code for receive and trasmit remote IR data for example an hi-fi )

Code: Select all

void interrupt()
{
 if (TMR0IF_bit){
  TMR0IF_bit=0;
  TMR0H = 0b1011; // =hex 0b
  TMR0L = 0b11011100; // =dc

  LATC7_bit= ~LATC7_bit;  // led blinking
 }
  // INTERRUPT ON RA2
  if (INTF_bit)   // && INTE_bit
  {
    IR_flag = 1;
    INTF_bit = 0;
  }

}

Code: Select all

void main() {
    // PORT SET
TRISA=0b00000000;
TRISB=0b00000000;
TRISC=0b00000000;  //0=output, 1=input
TRISA.B2 = 1; // Set RA2 as input for Infrared Decoder interrupt
WPUA = 0b00000100;   // set pull-up for RA2 (IR interrupt)
PORTA=0; PORTB=0; PORTC=0;

// Disable comparators
  C1ON_bit = 0;
  C2ON_bit = 0;
  CM1CON0=0;
  CM2CON0=0;
  ANSELA = 0x00;  // configure all PORTA pins as digital
  ANSELB = 0x00;  // configure all PORTB pins as digital
  ANSELC = 0b00001111;
  
  UART1_Remappable_Init(9600);
  RC5PPS = 0x14;// 00010100 PIN Rxy OUTPUT SOURCE SELECTION REGISTER source is TX/CK(1)                                                           // UART Tx output RC5
  RXPPS = 0x14; // 00010100 PERIPHERAL xxx INPUT SELECTION input is RC4 RX                                                          // UART RX input RC4
  Delay_ms(100);                                                              // UART settle time


  arm_interrupt_timer0();
  
  // REMAPPABLE INT PIN ON RA2 (on datasheet pag.164)
  INTPPS = 0x02; //INTPPS = 0b00000010;  //RA2 > INT 0x0002
  Delay_ms(100);
  INTEDG_bit = 0;  //Interrupt on falling edge of INT pin (fronte di discesa)
  PEIE_bit = 1;
  //INTE_bit = 1;
  GIE_bit = 1;
  IR_flag = 0;
    
    UART1_Write_CText (" Test : \r\n");
    
    while(1){
        if(IR_flag) {IR_flag=0; UART1_Write_CText("Interrupt on RA2 OK!!\r\n");
        }
    }	// WND WHILE(1)
}	// END MAIN
Attachments
TestInterruptRA2-Uart16F18346-V1.0.zip
(42.02 KiB) Downloaded 23 times
Screenshot_2022-11-15-16-16-39-00_99c04817c0de5652397fc8b56c3b3817.jpg
Screenshot_2022-11-15-16-16-39-00_99c04817c0de5652397fc8b56c3b3817.jpg (1.05 MiB) Viewed 770 times
InterruptRA2.jpg
InterruptRA2.jpg (235.27 KiB) Viewed 777 times
Last edited by leo73 on 19 Nov 2022 15:40, edited 1 time in total.

paulfjujo
Posts: 1555
Joined: 24 Jun 2007 19:27
Location: 01800 St Maurice de Gourdans France
Contact:

Re: I can't receive interrupt on RA2 16F(L)18346

#2 Post by paulfjujo » 15 Nov 2022 20:16

hello,

try to remove R31 and led !
direct connect to RA2
recopie RA2 status to another output with R + led

leo73
Posts: 252
Joined: 09 Jan 2014 15:45

Re: I can't receive interrupt on RA2 16F(L)18346

#3 Post by leo73 » 19 Nov 2022 15:10

Hello to every one,
I modified schematic how paulfjujo explaned me, i modified name of registers and i called they like: PIR0.INTF, INTCON.INTEDG, PIE0.INTE, INTCON.GIE insted to INTF_bit, INTEDG_bit, INTE_bit, GIE_bit; (Datasheet page 99)
Now when RA2 pin receive an LOW interrupt from TSOP RX IR SENSOR the interrupt is called.
I addition i connected led in other position between RA2 line and Vdd using a 670 ohm resistor. Looc the attachement.
Below there's code:

Code: Select all

void interrupt()
{
 if (TMR0IF_bit){
  TMR0IF_bit=0;
  TMR0H = 0b1011; // =hex 0b
  TMR0L = 0b11011100; // =dc

  LATC7_bit= ~LATC7_bit;  // led blinking
 }
  // INTERRUPT ON RA2 Datasheet page 99
  if (PIR0.INTF == 1)   // && INTE_bit
  {
    IR_flag = 1;
    PIR0.INTF = 0;
  }

}
All code:

Code: Select all

////////////////////////////// UART TEST ///////////////////
 //
 // PIN OUT:
 // RC5 --> UART TX
 // RC4 --> UART RX
 // RA2 --> TSOP1736 INFRARED RECEIVER CHIP (ACTIVE ON THE FALLING EDGE)
 //
 //////////////////////////////////////////////////////////////

// global variables


#define CLS 12
#define CR 13
#define LF 10
#define TAB 9

bit IR_flag;

//==================== INTERRUPT PROCEDURE =========================
void interrupt()
{
 if (TMR0IF_bit){
  TMR0IF_bit=0;
  TMR0H = 0b1011; // =hex 0b
  TMR0L = 0b11011100; // =dc

  LATC7_bit= ~LATC7_bit;  // led blinking
 }
  // INTERRUPT ON RA2
  if (PIR0.INTF == 1)   // && INTE_bit
  {
    IR_flag = 1;
    PIR0.INTF = 0;
  }

}

//================== END INTERRUPT PROCEDURE =======================




//===================== LOCAL FUNCTIONS ======================

void arm_interrupt_timer0(){
  T0CON0.T016BIT = 1; // Set timer 0 to work at 16bit
  // bin: 1000; // set prescaler at 1/256
  T0CON1.T0CKIPPS0=0;T0CON1.T0CKIPPS1=0;T0CON1.T0CKIPPS2=0;T0CON1.T0CKIPPS3=1;
  //bin: 011;  // Timer0 Clock Source Select bits-> HFINTOSC
  T0CON1.T0CS0=1;T0CON1.T0CS1=1;T0CON1.T0CS2=0;
  //bin= 0001; // set post scaler at 1/2
  T0CON0.T0OUTPS0=1; T0CON0.T0OUTPS1=0; T0CON0.T0OUTPS2=0;T0CON0.T0OUTPS3=0;
  INTCON         = 0xC0; // GLOBALiNTERRUPT=ENABLE; ENABLE ALL ACTIVE PERIF.INT.
  TMR0IE_bit         = 1;  // ENABLE TIMER 0 INTERRUPT
  T0CON0.T0EN = 1; // Start timer
 }

void disarm_interrupt()
{
 T0CON0.T0EN = 1; // stop timer 0
}

void CRLF1()
{
    UART1_Remappable_Write(CR);
    UART1_Remappable_Write(LF);
}

void UART1_Write_CText(const char *txt)
{

   while (*txt)
      UART1_Remappable_Write(*txt++);
   Delay_us(5);

}



void main() {
    // PORT SET
TRISA=0b00000000;
TRISB=0b00000000;
TRISC=0b00000000;  //0=output, 1=input
TRISA.B2 = 1; // Set RA2 as input for Infrared Decoder interrupt
//WPUA = 0b00000100;   // set pull-up for RA2 (IR interrupt)
PORTA=0; PORTB=0; PORTC=0;

// Disable comparators
  C1ON_bit = 0;
  C2ON_bit = 0;
  CM1CON0=0;
  CM2CON0=0;
  ANSELA = 0x00;  // configure all PORTA pins as digital
  ANSELB = 0x00;  // configure all PORTB pins as digital
  ANSELC = 0b00001111;//select PORTC ch:0,1,2,3 Acquairing Vu-Meter and Spectrum

  UART1_Remappable_Init(9600);
  RC5PPS = 0x14;// 00010100 PIN Rxy OUTPUT SOURCE SELECTION REGISTER source is TX/CK(1)                                                           // UART Tx output RC5
  RXPPS = 0x14; // 00010100 PERIPHERAL xxx INPUT SELECTION input is RC4 RX                                                          // UART RX input RC4
  Delay_ms(100);                                                              // UART settle time


  arm_interrupt_timer0();
  
  INTPPS = 0x02; //INTPPS = 0b00000010;  //RA2 > INT 0x0002
  Delay_ms(100);
  // Interrupt section in Datasheet page 99
  INTCON.INTEDG = 0;  //Interrupt on falling edge of INT pin (fronte di discesa)
  PIE0.INTE = 1;
  INTCON.GIE = 1;
  IR_flag = 0;
    
    UART1_Write_CText (" Test : \r\n");
    
    while(1){
        if(IR_flag) {IR_flag=0; UART1_Write_CText("Interrupt on RA2 OK!!\r\n");
        }
    }
}
Attachments
IMG_20221119_151657.jpg
IMG_20221119_151657.jpg (443.58 KiB) Viewed 704 times

Post Reply

Return to “mikroC PRO for PIC General”