Difference between nvic and pin interrupt

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Difference between nvic and pin interrupt

Jump to solution
569 Views
elb1
Contributor III

Hello,

I am using s32k142 MCU, and I want to implment a gpio interrupt on one of the MCU pins, So I am getting rising edges from another device and i need to count the number of rising edges received.
So each time i am receiving rising edge i generate an interrupt and i increment a counter variable.

To do this i have used a simple interrupt logic which consist of:
1. Configure IRQC in PCR register for the appropriate pin:
port->PCR[pin] |= PORT_PCR_IRQC_MASK & PORT_PCR_IRQC(interrupt); 

2. Register and enable interrupt on PORTC_IRQn (because the interrupt pin is PTC7.

3. Once i am in the isr i clear ISF flag from PCR register: PORT_PCR_ISF(1U)


My question here is:
1. Is this logic i implemented sufficient and correct ?
2. I have seen in some examples the usage of "S323_NVIC, ISER, ICER, etc...", Is this another way to do interrupts ? or it should go with the one that i already have, or what is the difference.

Thank you in advance.

Tags (3)
0 Kudos
1 Solution
520 Views
Senlent
NXP TechSupport
NXP TechSupport

Hi@elb1

1.yes, enable,disable,clean interrupt like this..

2.This is not required, just make sure the watchdog is turned off when you are not using it

View solution in original post

0 Kudos
3 Replies
532 Views
Senlent
NXP TechSupport
NXP TechSupport

Hi@elb1

Q1.Yes and  you can refer to the demo below.

Q2.hard to explain to you, you need to read the S32K-RM for detail:

chapter :7.2 Nested Vectored Interrupt Controller (NVIC) Configuration

#include "device_registers.h"

/*! Port PTC12, bit 12: FRDM EVB input from BTN0 [SW2]*/
#define PTC12 12
int counter = 0;

void WDOG_disable (void)
{
  WDOG->CNT=0xD928C520;     /* Unlock watchdog 		*/
  WDOG->TOVAL=0x0000FFFF;   /* Maximum timeout value 	*/
  WDOG->CS = 0x00002100;    /* Disable watchdog 		*/
}

void S32_NVIC_EnableIRQ(IRQn_Type IRQn, int Priority)
{
	/* enable interrupt */
	S32_NVIC->ISER[(uint32_t)((int32_t)IRQn) >> 5] = (uint32_t)(1 << ((uint32_t)((int32_t)IRQn) & (uint32_t)0x1F));
	S32_NVIC->IP[IRQn] = Priority;
}


void PORTC_IRQHandler(void)
{
	counter++;
	PORTC->PCR[PTC12] |= PORT_PCR_ISF_MASK;
}

int main(void)
{
	/* Disable Watchdog in case it is not done in startup code */
	WDOG_disable();

	/* Enable clocks to peripherals (PORT modules) *//* Enable clock to PORT D*/
	PCC-> PCCn[PCC_PORTC_INDEX] = PCC_PCCn_CGC_MASK;

	/* Configure port C12 as GPIO input (BTN 0 [SW2] on EVB) */
	PTC->PDDR &= ~(1<<PTC12);
	PORTC->PCR[12] = PORT_PCR_MUX(1)|PORT_PCR_PFE_MASK|PORT_PCR_IRQC(0x9); /* Port C12: MUX = GPIO, input filter enabled */

	S32_NVIC_EnableIRQ(PORTC_IRQn,9);

	for(;;)
	{
		;
	}
}

 

 

0 Kudos
526 Views
elb1
Contributor III

Hello, thank you for your response.
So, both of them are actually needed (configuration using PCR register, AND NVIC)
1. nvic is some how the responsible for interrupt registering and enabling, right ?
2. I have another question, is it mandatory to disable watchdog before we enable interrupt than enable it again ? 

0 Kudos
521 Views
Senlent
NXP TechSupport
NXP TechSupport

Hi@elb1

1.yes, enable,disable,clean interrupt like this..

2.This is not required, just make sure the watchdog is turned off when you are not using it

0 Kudos