Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pic32 Interrupts
29-05-2012, 09:46 PM,
#11
RE: Pic32 Interrupts
Maybe you should define pin D3 as an input in the setup.

pinMode(3,INPUT);

Not sure......

JP

(29-05-2012, 09:35 PM)MarSch Wrote: Hi there,

thanks a lot for the help, now it builds at least.

But unfortunately, that's it pretty. If I connect the 3.3V pin of the board with D3, I'd expect the ISR to be jumped in. However, nothing happens at all.

I made up the example below as simple as possible to prevent stupid errors. Maybe someone spots the problem, but I suspect it's not as easy and the Unlock/Lock functions don't do what they're expected to.

Any ideas?

/MarSch


Code:
/* ========================================================================== */
/*                                                                            */
/*   InterruptWithPeripheralPinSelect.c                                       */
/*   (c) 2012 Pinguino Forum (with hints from J.P. Mandon)                    */
/*                                                                            */
/*   This example shows how to use external interrupts INT1-INT4 on the       */
/*   MX 220 via Peripheral Pin Select (PPS).                                  */
/*                                                                            */
/*                                                                            */
/*   Helpful resources:                                                       */
/*     http://www.olimex.com/dev/pic32-pinguino-mx220.html                    */
/*     http://ww1.microchip.com/downloads/en/DeviceDoc/61168D.pdf             */
/*     Pinguino (p32/include): p32mx220f032d.h, interrupt.c, p32mxgeneric.h   */
/*                                                                            */
/* ========================================================================== */

// -----------------------------------------------------------------------------
//  Interrupt setup
// -----------------------------------------------------------------------------
  
// Initialize interrupt vector
// From p32mxgeneric.h
//   #define _IFS0_INT1IF_POSITION                    0x00000007  =   7
void ISR_wrapper_vector_7(void)  __attribute__ ((section (".vector_7")));

// Assign ISR handlers to interrupt vector
void ISR_wrapper_vector_7(void)  { Int1Interrupt(); }

// Declare interrupt handler
void Int1Interrupt(void) __attribute__ ((interrupt));


// -----------------------------------------------------------------------------
//  Global variables
// -----------------------------------------------------------------------------
  
// Assign pin variable
const int ledPin = 13;

// Define and initialize flag (declare volatile when used in ISRs)
volatile boolean blinkFlag = FALSE;


// -----------------------------------------------------------------------------
//  ISR handlers
// -----------------------------------------------------------------------------

// Implement interrupt handlers
void Int1Interrupt(void)
{
  if (IFS0bits.INT1IF) // interrupt flag for INT1
  {
    blinkFlag = TRUE;
    IFS0bits.INT1IF = 0; // clear the interrupt flag
  }
}


// -----------------------------------------------------------------------------
//  Setup pins and peripheral functionality
// -----------------------------------------------------------------------------
  
// Initialize MCU
void setup()
{
  // Unlock MCU assignment to use PPS
  SystemUnlock();
  CFGCONbits.IOLOCK=0;            // unlock configuration
  CFGCONbits.PMDLOCK=0;
  
  // Assign external interrupts
  // Bit assignments are listed on page 146 of the datasheet
  INT1Rbits.INT1R = 0b0110; // Define RPC2 as INT1 (MX220 pin D3)

  // Lock PPS facility again
  CFGCONbits.IOLOCK=1; // relock configuration
  CFGCONbits.PMDLOCK=1;
  SystemLock();
    
  // Interrupt setup
  IEC0bits.INT1IE=0; // disable this interrupt
  INTCONbits.INT1EP=0; // edge polarity for this interrupt ( rising edge )
  IPC1bits.INT1IP=1; // interrupt priority
  IPC1bits.INT1IS=1; // interrupt sub priority
  IEC0bits.INT1IE=1; // enable this interrupt
    
  // Initialize pin 13 (onboard LED green) as output
  pinMode(ledPin, OUTPUT);
  
  // Tell the world I'm alive
  digitalWrite(ledPin, HIGH);
  delay(500);
  digitalWrite(ledPin, LOW);
}

void loop()
{
  if (blinkFlag == TRUE)
  {
    digitalWrite(ledPin, HIGH);
    delay(1000);
    digitalWrite(ledPin, LOW);
    blinkFlag = FALSE;
  }
}
Reply
30-05-2012, 12:02 PM,
#12
RE: Pic32 Interrupts
It's obviously not the input-statement, though that might be necessary as well.

I tried all sorts of things, including setting the PPS in io.h (as I read that the PIC can only be unlocked/locked one time after boot), to no avail.

To exclude issues with PPS, I've been switching using INT0 (hardwired) as suggested to the OP of this thread, in the first place. Interestingly, that hasn't changed nothing at all.

It would be interesting if somebody with a Pinguino Micro could run the code below (pin assignment change should be sufficient) and see if interrupt INT0 works.

This would at least be an indicator that it is a MX220 related problem.

Code:
/* ========================================================================== */
/*                                                                            */
/*   ExternalInterrupt.c                                                      */
/*   (c) 2012 Pinguino Forum (with hints from J.P. Mandon)                    */
/*                                                                            */
/*   This example shows how to use external interrupt INT0 on the MX 220      */
/*                                                                            */
/*                                                                            */
/*   Helpful resources:                                                       */
/*     http://www.olimex.com/dev/pic32-pinguino-mx220.html                    */
/*     http://ww1.microchip.com/downloads/en/DeviceDoc/61168D.pdf             */
/*     Pinguino (p32/include): p32mx220f032d.h, interrupt.c, p32mxgeneric.h   */
/*                                                                            */
/* ========================================================================== */

// -----------------------------------------------------------------------------
//  Interrupt setup
// -----------------------------------------------------------------------------

// Initialize interrupt vector
// From p32mxgeneric.h
//   #define _IFS0_INT0IF_POSITION                    0x00000003  =   3
void ISR_wrapper_vector_3(void)  __attribute__ ((section (".vector_3")));

// Assign ISR handlers to interrupt vector
void ISR_wrapper_vector_3(void)  { Int0Interrupt(); }

// Declare interrupt handler
void Int0Interrupt(void) __attribute__ ((interrupt));  
      
        
// -----------------------------------------------------------------------------
//  Global variables
// -----------------------------------------------------------------------------
  
// Assign pin variable
const int extIntrPin = 8;  // according to Olimex manual
const int redLedPin = 9;
const int greenLedPin = 13;

// Define and initialize flag (declare volatile when used in ISRs)
volatile int blinkFlag = 0;


// -----------------------------------------------------------------------------
//  ISR handlers
// -----------------------------------------------------------------------------

// Implement interrupt handlers
void Int0Interrupt(void)
{
  if (IFS0bits.INT0IF) // interrupt flag for INT0
  {
    blinkFlag = 1;
    IFS0bits.INT0IF = 0; // clear the interrupt flag
  }
}

                        
// -----------------------------------------------------------------------------
//  Setup pins and peripheral functionality
// -----------------------------------------------------------------------------

    
// Initialize MCU
void setup()
{
  // Interrupt setup
  pinMode(extIntrPin, INPUT);

  IEC0bits.INT0IE=0; // disable this interrupt
  INTCONbits.INT0EP=1; // edge polarity ( 1 rising, 0 falling edge )
  IPC0bits.INT0IP=1; // interrupt priority (was 7)
  IPC0bits.INT0IS=1; // interrupt sub priority (was 0)
  IEC0bits.INT0IE=1; // enable this interrupt
  IFS0bits.INT0IF = 0; // clear flag  
        
  // Initialize LED pins as output
  pinMode(redLedPin, OUTPUT);
  pinMode(greenLedPin, OUTPUT);
  
  // Tell the world I'm alive
  digitalWrite(greenLedPin, HIGH);
  digitalWrite(redLedPin, HIGH);
  delay(1000);
  digitalWrite(greenLedPin, LOW);
  digitalWrite(redLedPin, LOW);
}

void loop()
{
  digitalWrite(greenLedPin, HIGH);
  delay(100);
  digitalWrite(greenLedPin, LOW);
  delay(100);    
  
  if (blinkFlag)
  {
    digitalWrite(redLedPin, HIGH);
    delay(2000);
    digitalWrite(redLedPin, LOW);
    blinkFlag = 0;
  }
}
Reply
30-05-2012, 04:09 PM,
#13
RE: Pic32 Interrupts
Well, after putting

Code:
IntConfigureSystem(INT_SYSTEM_CONFIG_MULT_VECTOR);

at the start of setup(), it looks like it works. That's the good news.

The bad one is that I shoot in my own foot with that. D8 is BUT on the MX220, which is necessary to put the device in bootloader mode. So as it looks at the moment, I'm unable to download any new code anymore.

Any good advice regarding debricking would be highly appreciated. Thanks in advance. (I don't have a programmer to reflash the bootloader, BTW).

/MarSch
Reply
30-05-2012, 07:30 PM,
#14
RE: Pic32 Interrupts
D8 shouldn't be configured as long as you stay in bootloader mode.
Hit Reset button, keep the user button switched and you should stay in bootloader mode.
What are you exactly seeing ?

JP

(30-05-2012, 04:09 PM)MarSch Wrote: Well, after putting

Code:
IntConfigureSystem(INT_SYSTEM_CONFIG_MULT_VECTOR);

at the start of setup(), it looks like it works. That's the good news.

The bad one is that I shoot in my own foot with that. D8 is BUT on the MX220, which is necessary to put the device in bootloader mode. So as it looks at the moment, I'm unable to download any new code anymore.

Any good advice regarding debricking would be highly appreciated. Thanks in advance. (I don't have a programmer to reflash the bootloader, BTW).

/MarSch
Reply
31-05-2012, 09:20 AM,
#15
RE: Pic32 Interrupts
It seems I can't get into bootloader mode, since pressing the BUT button triggers an external interrupt in my code, which obviously interferes with the bootloader activation sequence.

Trying to use the sequence that's been successful until now results in a statically lit red LED:

1. Press RESET button, hold down (if I hit BUT first, the interrupt gets triggered)
2. Press BUT button, hold down
3. Release RESET button

Now green LED is flashing 1x for about 250 ms, after this the red LED lights up and stays lit.
This sequence is repeated every time I hit the RESET button, as long as I hold BUT down.

4. Release BUT button

No change (no flashing), the LEDs remain it the state they've been after releasing the RESET button.

If the MX-220 shows the red LED only, the IDE doesn't recognize it as being in bootloader mode.

I'd be happy about any suggestion on how to change this. Thanks.
Reply
31-05-2012, 11:20 AM,
#16
RE: Pic32 Interrupts
Try holding the reset while you plug in the USB cable and then add the but then release the reset.
PIC32-Pinguino-OTG Rev C and PIC32-PINGUINO-MICRO rev.B
Win XP SP3
r381 x.3 Big Grin
AND spi.c {} error fixed
AND sdmmc.c pin error fixed
AND diskio.c fixed, MICRO can't use the RTCC
AND analog.c fixed for MICRO
Reply
31-05-2012, 11:39 AM, (This post was last modified: 31-05-2012, 11:41 AM by pingotg.)
#17
RE: Pic32 Interrupts
Unless the bootloader has been overwritten, which does not sound to be the case, the point is that Reset starts executing the bootloader. The bootloader will jump to your (now broken) app but only if the User Button is not pressed. So make sure you are pressing it all the time as you release Reset.

If the above does not work then you musy have overwritten the bootloader. Then you'd need to find out how (to avoid it in future) and either buy/borrow a PICkit(2 or 3) so you can restore the bootloader or junk your Pinguino board.

John
Reply
31-05-2012, 11:40 AM, (This post was last modified: 31-05-2012, 04:50 PM by MarSch.)
#18
RE: Pic32 Interrupts
I have no idea how I might have overwritten the bootloader. Its like it starts the alternating blink sequence, but gets stuck immediately.

Does anyone have a clue what the blink sequence I encounter means?

Holding down the BUT button while plugging in the USB jack results in the same behaviour BTW: green blinks shortly, then red is constantly on.
Reply
31-05-2012, 08:11 PM, (This post was last modified: 31-05-2012, 09:06 PM by MarSch.)
#19
RE: Pic32 Interrupts
As I have another MX220 here, I wanted to proceed with it until the PICkit arrives...

However, funny enough, it shows the same behaviour though its a pristine Pinguino that I just unpacked. It seems to run a firmware that is just blinking the red LED. When I hit the BUT button, it stops the red one and blinks the green one instead. Can anybody confirm this is the state of delivery?

What I do now (and what seems to be the way to get into bootloader mode):
1. Hold down BUT (with an optional RESET press/release)
2. Hold down RESET, release RESET
3. Release BUT

But no alternating blink sequence here as well, instead the same as described avobe (short green, static red).

The reason might be an entirely different one, but can please anybody more intimate with the bootloader explain what that means?

NOTE: I found out that the problem was related to the driver on my system (Windows7 32 bit). After rebooting the machine, I again see the alternating flash sequence as I would expect it. I can upload code again. Strange, though obviously a matter of fact.
Reply
31-05-2012, 09:17 PM,
#20
RE: Pic32 Interrupts
Sounds like Windows was holding the board in a state where it could not operate properly, whether by a bad voltage or odd handshake or some other way.

Rebooting Windows seems to be needed often.....

John
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)