News:

Let's find out together what makes a PIC Tick!

Main Menu

dsPIC33CK256MP508 INT1 doesn't fire

Started by Wimax, Aug 02, 2025, 04:36 PM

Previous topic - Next topic

Wimax

Hello everybody !

I have a problem with the INT1 interrupt on a dsPIC33CK256MP508 as I can't get it working properly.
I defined the selected input pin for this function using the PPS macro:
PPS_Input(cIn_Pin_RP75, cIn_Fn_INT1) ' Map INT1 RX pin to RD11I defined the pin used as an input with the "PinInput" instruction.
I initialised the interrupt:

    IFS0bits_INT1IF=0
    IPC3bits_INT1IP0 =1
    IPC3bits_INT1IP1 =1
    IPC3bits_INT1IP2 =1
    INTCON2bits_INT1EP=1 '1 = External Interrupt on negative edge
    IEC0bits_INT1IE= 1 '1 = External Interrupt on edge is active 
    INTCON2bits_GIE=1

and then the interrupt handling routine, that is never invoked.

Isr INT1Interrupt
HRSOutLn "Test" ' Simple test line 
IFS0bits_INT1IF=0
EndIsr


I added these interrupt priority lines within the .def file:
' Definisco IPC3 priority bits for external interrupt 1

$define IPC3bits_INT1IP0 IPC3.12
$define IPC3bits_INT1IP1 IPC3.13
$define IPC3bits_INT1IP2 IPC3.14
I checked both with the oscilloscope and in the main programme, using a simple control loop, that the pin status changes, but the interrupt is not triggered at all.

I add that trying with INT2 instead of INT1, the program works, but I don't understand why !

diebobo

Wimax,

A year + ago there where some issues with the .def .ini files of this device.. are u using latest version of compiler ?

Wimax

Hi Diebobo,

Yes, but I added some entries to the standard .def file as those for INTx interrupt priority. I tried INT1 and it is KO while INT2 is OK.


trastikata

Hello Wimax,

I can't check the assembler code at the moment, but can you try setting the the PPS manually by modifying the appropriate registers.

diebobo

Wimax, can u post a complete test code from line 0 to end ? I''ve got that device here on a testboard.. can spend few minutes on it 2 morrow if u post code.

I say whole code because sometimes that is important ..

Wimax

Hi Diebobo,

I selected this part of the main code that's very long, but if I select INT2 instead INT1 all is ok, the problem seems to be INT1:

'****************************************************************************
'*  Name    : 33CK256MP508 INT1 Test                                        *
'****************************************************************************

Device = 33CK256MP508
Declare  Xtal=200   ' MCU Clock frequency
Declare Hserial_Baud=38400 ' USART1 Baud rate 

PPS_Input(cIn_Pin_RP75, cIn_Fn_INT1) ' Map INT1 RX pin to RD11


Config FSEC       =BWRP_OFF, BSS_DISABLED, BSEN_OFF, GWRP_OFF, GSS_DISABLED, CWRP_OFF, CSS_DISABLED, AIVTDIS_OFF
Config FOSCSEL    =FNOSC_FRC, IESO_OFF
Config FOSC       =POSCMD_XT, OSCIOFNC_ON, FCKSM_CSECMD, PLLKEN_OFF, XTCFG_G0, XTBST_ENABLE   ' Using 8 MHz external quartz
Config FWDT       =SWDTPS_PS2147483648, RCLKSEL_LPRC
Config FPOR       =BISTDIS_DISABLED
Config FICD       =ICS_PGD3, JTAGEN_OFF, NOBTSWP_DISABLED
Config FDMT       =DMTDIS_OFF
Config FDEVOPT    =ALTI2C1_OFF,ALTI2C2_OFF,ALTI2C3_ON, SMBEN_SMBUS, SPI2PIN_PPS 
Config FALTREG    =CTXT1_OFF, CTXT2_OFF, CTXT3_OFF, CTXT4_OFF
Config FBOOT      =BTMODE_SINGLE



PinInput PORTD.11   'Defined as digital input

Isr INT1Interrupt 'External Interrupt INT1 ISR

HRSOutLn "Hello! I'm here !" ' If INT1 is fired...write something
       
IFS0bits_INT1IF=0

EndIsr



'----------------------------------------------------------------------------------
' Setup the device to operate at 200MHz with external quartz
' Input     : None
' Output    : None
' Notes     : Waits for the oscillator to become stable
'
Proc IntOsc_200MHz()

CLKDIV=$3001          ' FRCDIV FRC/1, PLLPRE 1, DOZE 1:8
PLLFBD=100
OSCTUN=$00
PLLDIV=$21            ' POST1DIV 1:2, VCODIV FVCO/4, POST2DIV 1:1
ACLKCON1=$0101        ' FRCSEL FRC, APLLPRE 1:1
APLLFBD1=$C8
APLLDIV1=$42          ' APOST1DIV 1:4, APOST2DIV 1:2, AVCODIV FVCO/4*)
Write_OSCCON($0301)

While OSCCONbits_OSWEN <> 0 : Wend      ' Wait for the clock switch to occur
While OSCCONbits_LOCK <> 1 : Wend       ' Wait for the oscillator to lock
EndProc

Proc Setup_INT()
   
    IFS0bits_INT1IF=0
'*********************************
' Added to .def file and used here. Interrupt priority set to max

    IPC3bits_INT1IP0=1
    IPC3bits_INT1IP1=1
    IPC3bits_INT1IP2=1
'*********************************
    INTCON2bits_INT1EP=1 '1 = External Interrupt on negative edge
    IEC0bits_INT1IE=1 '1 = External Interrupt on edge is active 
    INTCON2bits_GIE=1 ' Enable global Interrupt
   
 
 
EndProc




Main:

IntOsc_200MHz()  ' Set the device to operate at 200 MHz
 
Setup_INT() ' Init INT1 interrupt
       
'*********************************
'*     ENTERS AN INFINITE LOOP   *
'*********************************
     
Do
Loop


diebobo

#6
Wimax,

Took me a while to found this one.. Buttttt, i think there is a fault in the datasheet...

Try this code:

RPINR0.Byte1 = 75
Instead of

PPS_Input(cIn_Pin_RP75, cIn_Fn_INT1) ' Map INT1 RX pin to RD11
The explaining is a bit difficult this late, and depending on your understanding .. But with the PPS system u can map a function to a pin, and 1 Adres has a lowerbyte and a higherbyte for 2 mappings. For INT1 this is the highbyte of RPINR0 according to 1 page and according to another page that highbyte is not used. So there is a mismatch in the datasheet on 1 page, and on the other. See images below..

In my test setup i couldn't get it working either, Int 2 and 3 worked fine, 1 not. So i digged...

Try ! and let me know :)

afbeelding 2.png

afbeelding 1.png

Wimax

Hi Diebobo,

Thank you for taking the time to address this issue.
I didn't try with a direct assignment insted of using the macro yet, but I spent some minutes digging the datasheet.
It seems that under normal operation, writes to the RPINRx and RPORx registers are not allowed and it is necessary to perform an hardware unlock through the IOLOCK bit.
Then it is reported that after a RESET the IOLOCK bit is set to 0 so...it's not necessary to unlock it, but it's better to do that for safety related reasons.
When the MCU exits from a RESET "all RPINRx registers reset to '1's and RPORx registers reset to '0's, this means all PPS inputs are tied to VSS, while all PPS outputs are disconnected", I think that this explains why all the bit of byte1 of RPINR0 register are set to '1'on table 4-14.
  • INT0 cannot be assigned using PPS function.
  • INT1 is managed by byte1 of RPINR0 register, byte0 is unused.
  • INT2 and INT3 are managed by the same RPINR1 register using byte0 and byte1 respectively.

So, if we assume that IOLOCK is effectively set to '0' after a reset, writing RPINR0.Byte1 = 75 should work.
I could add that, in order to be effectively confident of the IOLOCK status, the RPINR0 setting could be anticipated by the unlocking sequence described by Microchip:
"To set or clear IOLOCK, the NVMKEY unlock sequence must be executed:
1. Write 0x55 to NVMKEY.
2. Write 0xAA to NVMKEY.
3. Clear (or set) IOLOCK as a single operation. IOLOCK remains in one state until changed."

Anyway...I still don't understand why the PPS macro works with INT2 and it doesn't with INT1.

diebobo

So, lesson for me.. don't read datasheets late at night anymore.. i clearyly was confused, both pictures show that the highbyte should be written for INT1..

The explanation why PPS function does not work is easy to understand ..

PPS_Input(cIn_Pin_RP75, cIn_Fn_INT1) Results in ASM code of RPINR0.Byte0 = 75, while it should be RPINR0.Byte1 = 75

So the PPS function generates wrong ASM code... Who to blaim i check now :)

Wimax

You were very kind to spend your time trying to solve my problem, don't worry... I constantly make mistakes with Microchip datasheets, but I must also say that they go to great lengths to mislead users.
You did the right thing by checking the assembler, it was the most logical thing to do, in fact now I have the same doubt as you...Who should we blame ? ;D

diebobo

Wimax,

Search for File : 33CK256MP508.def, for me it's here : C:\Program Files (x86)\ProtonIDE\PDS\Includes\Defs

Line +/- 1347, $define RPINR0bits_INT1R RPINR0.Byte0  change it to : $define RPINR0bits_INT1R RPINR0.Byte1

Now your PPS function should work again...

The blaiming part, that's actually easy ---> Les !!! haha, nah.. he takes the info from the device files from Microchip i believe, so an automatic scraper thingy if i remember correctly.

@top204 It this something u can / should change on yr end so the device / definition files are also correctly installed ?

Wimax

Thank you very, very much !  ;)