Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pic32 Interrupts
31-05-2012, 09:55 PM,
#21
RE: Pic32 Interrupts
What's still not working is the PPS interrupt setup.

I proved that INT0 (hardwired) works the way it should, but using the peripheral pin select feature with the other pins does not yield any result. They just don't react at all.

Has anybody successfully used mapped interrupts with Pinguino by now? All examples I've seen by now use the hardwired ones.

/marsch
Reply
31-05-2012, 10:08 PM,
#22
RE: Pic32 Interrupts
Sounds like time to hunt hard in the Microchip data sheets.

Sorry!

John
Reply
01-06-2012, 02:47 PM,
#23
RE: Pic32 Interrupts
I've been ending up in trying the following to track down why the PPS interrupts aren't going to be recognized.

Interestingly, the value of INT2Rbits.INT2R is always 0, regardless of what I'm setting it to (and how).

Code:
SYSKEY = 0x0;// ensure OSCCON is locked
  SYSKEY = 0xAA996655;// Write Key1 to SYSKEY
  SYSKEY = 0x556699AA;// Write Key2 to SYSKEY    

  INT2Rbits.INT2R = 0b0111;

  if (INT2Rbits.INT2R == 0b0111)
  {
    blink(greenLedPin, 100, 0, 1);  
  }
  else if (INT2Rbits.INT2R == 0)
  {
    blink(redLedPin, 100, 0, 1);
  }

  SYSKEY = 0x0;// ensure OSCCON is locked

I can find no indication that this register is read-only, so I'd suspect it is never really set.

Ideas?
Reply
01-06-2012, 03:29 PM,
#24
RE: Pic32 Interrupts
Hi MarSch,

following on from pingotg's comment above, there is a comment below Register 12-2: [pin name]R: Peripheral Pin Select Input Register(1) on Page 12-6 for Section 12. I/O Ports of the PIC32 family reference manual (61120E)

"Note 1: Register values can only be changed if the IOLOCK Configuration bit (CFGCON<13>) = 0.
"

Have you dealt with this?

Regards
Board = PIC32-Pinguino-OTG Rev C
OS = Linux Unbuntu 11.10 till 26 Apr 2012
OS = Linux Unbuntu 12:04 from 27 Apr 2012
Reply
01-06-2012, 04:02 PM,
#25
RE: Pic32 Interrupts
I left to mention this; however the IOLOCK bit is cleared as described in http://ww1.microchip.com/downloads/en/De...70190E.pdf (page 30-11).

Here's the full listing:

Code:
#include <system.c>
#include <interrupt.c>
#include <delay.c>

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

// Initialize interrupt vectors
// From p32mxgeneric.h
//   #define _IFS0_INT2IF_POSITION                    0x0000000B  =  11
void ISR_wrapper_vector_11(void)  __attribute__ ((section (".vector_11")));

// Assign ISR handlers to interrupt vector
void ISR_wrapper_vector_11(void)  { Int2Interrupt(); }

// Declare interrupt handler
void Int2Interrupt(void) __attribute__ ((interrupt));  
            
        
// -----------------------------------------------------------------------------
//  Global variables
// -----------------------------------------------------------------------------
  
// Assign pin variable
const int extIntrPin = 2;  // according to Olimex manual wiring layout
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 Int2Interrupt(void)
{
  if (IFS0bits.INT2IF) // interrupt flag for INT0
  {
    blinkFlag = 1;
    IFS0bits.INT2IF = 0; // clear the interrupt flag
  }
}

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


// Initialize MCU
void setup()
{
  IntConfigureSystem(INT_SYSTEM_CONFIG_MULT_VECTOR);    // interrupt mode (interrupt.c)

  // 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
  INT2Rbits.INT2R = 0b0111; // Define RPC3 as INT2 (MX220 pin D2)

  // Lock PPS facility again
  CFGCONbits.IOLOCK=1; // relock configuration
  CFGCONbits.PMDLOCK=1;
  SystemLock();  
    
  IEC0bits.INT2IE=0;    // disable this interrupt
  INTCONbits.INT2EP=1;  // edge polarity ( 1 rising, 0 falling edge )
  IPC2bits.INT2IP=7;    // interrupt priority (was 7)
  IPC2bits.INT2IS=1;    // interrupt sub priority (was 0)
  IEC0bits.INT2IE=1;    // enable this interrupt
  IFS0bits.INT2IF = 0;  // clear flag  

  IntEnableInterrupts();        
        
  // Interrupt setup
  pinMode(extIntrPin, INPUT);        
          
  // 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()
{
  blink(greenLedPin, 100, 0, 1);  
  
  if (INT2Rbits.INT2R == 0b0111)
  {
    blink(redLedPin, 2000, 0, 1);  
  }
  else if (INT2Rbits.INT2R == 0)
  {
    blink(redLedPin, 50, 0, 1);
  }
  
  // ISR    
  if (blinkFlag)
  {
    blink(redLedPin, 500, 0, 5);
    blinkFlag = 0;
  }
}

void blink(int ledPin, int onTime, int offTime, int times)
{
  int i;
  for (i = 0; i < times - 1; i++)
  {
    digitalWrite(ledPin, HIGH);
    delay(onTime);
    digitalWrite(ledPin, LOW);
    delay(offTime);
  }

  digitalWrite(ledPin, HIGH);
  delay(onTime);
  digitalWrite(ledPin, LOW);
}
Reply
01-06-2012, 04:30 PM,
#26
RE: Pic32 Interrupts
It's now nearly plain C for a PIC32. Probably worth going the rest of the way to C (i.e. no Pinguino stuff) then ask either Microchip (tech support) or in their forum.

Or just ask tech support / forum for a sample doing PPS. I've always got good answers from tech support, including sample code quite often.

John
Reply
01-06-2012, 07:00 PM,
#27
RE: Pic32 Interrupts
Well, I must admit you're right. I could have done this natively with far less effort, most probable because the potential user group facing such an issue on a naked PIC is larger.

What's making it harder with Pinguino is that the pins are preconfigured, so the initial state it hard to know unless I peek into all relevant files. Additionally, I can't use plib.h that easily. Well, I could, but this would make the botchjob only worse as functions exist in Pinguino files whose signature differs only in case.

Indeed, that's been exactly the opposite of my motivation in getting a Pinguino: I found it appealing not having to become very intimate with the underlying MCU architecture this time.
Reply
01-06-2012, 07:24 PM,
#28
RE: Pic32 Interrupts
To use something such as PPS - or even to find it exists - you're well beyond the simple features of a quite recent and incomplete project like Pinguino.

I expect PPS can be used even with Pinguino, if it works with the chip and you find how to use it.

John
Reply
06-06-2012, 02:39 AM,
#29
RE: Pic32 Interrupts
Well, io.c has the following, which is PPS as well (and those work, at least to the point where I see a difference in behaviour for PWM):

Code:
// PIC32 Peripheral Remappage
void IOsetRemap()
{
#if defined(PIC32_PINGUINO_220)
    SystemUnlock();
    CFGCONbits.IOLOCK=0;            // unlock configuration
    CFGCONbits.PMDLOCK=0;
    #ifdef __SERIAL__
        U2RXRbits.U2RXR=6;            // Define U2RX as RC8 ( D0 )
        RPC9Rbits.RPC9R=2;            // Define U2TX as RC9 ( D1 )
        U1RXRbits.U1RXR=2;            // Define U1RX as RA4 ( UEXT SERIAL )
        RPB4Rbits.RPB4R=1;            // Define U1TX as RB4 ( UEXT SERIAL )
    #endif
    #ifdef __SPI__
        SDI1Rbits.SDI1R=5;            // Define SDI1 as RA8 ( UEXT SPI )
        RPA9Rbits.RPA9R=3;            // Define SDO1 as RA9 ( UEXT SPI )
    #endif
    #ifdef __PWM__
        RPC2Rbits.RPC2R  =0b0101;    // PWM0 = OC3 as D2  = RC2
        RPC3Rbits.RPC3R  =0b0101;    // PWM1 = OC4 as D3  = RC3
        RPB5Rbits.RPB5R  =0b0101;    // PWM2 = OC2 as D11 = RB5
        RPB13Rbits.RPB13R=0b0110;    // PWM3 = OC5 as D12 = RB13
        RPB15Rbits.RPB15R=0b0101;    // PWM4 = OC1 as D13 = RB15
    #endif
    CFGCONbits.IOLOCK=1;            // relock configuration
    CFGCONbits.PMDLOCK=1;    
    SystemLock();
#endif
}

It seems this is an issue particularly affecting the interrupts.

/M
Reply
06-06-2012, 09:11 AM, (This post was last modified: 06-06-2012, 09:12 AM by pingotg.)
#30
RE: Pic32 Interrupts
Where are you going (trying to go) with this? It is fairly obscure and not really anything to do with Pinguino but is instead very clearly a PIC32 issue. It belongs on their forum or their tech support or the like. You might with a low probability get a reply here but I very much doubt it. Good luck.

I don't mean you must not ask or any like thing, but I wonder what the point is bearing in mind how obscure it is and how chip-specific it is.

John
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)