Interrupt S32K146

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

Interrupt S32K146

3,932 Views
Khaledag
Contributor II

I am trying to read the Interrupt of my Accelerometer Sensor. 
I found a code on the Forum here, and I tested it with the Buttons on the side of the board and worked. 
But when I try to check the Interrupt of my Sensor I see nothing, am I configuring the Pin right? 
Its pin PTE8
Here is the code: 

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++;
PORTE->PCR[PTE8] |= PORT_PCR_ISF_MASK;
}
  PCC-> PCCn[PCC_PORTE_INDEX] = PCC_PCCn_CGC_MASK;
 
/* Configure port E8 as GPIO input  */
  PTE->PDDR &= ~(1<<PTE8);
  PORTE->PCR[8] = PORT_PCR_MUX(1)|PORT_PCR_PFE_MASK|PORT_PCR_IRQC(0x9); /* Port E8: MUX = GPIO, input filter enabled */
 
  S32_NVIC_EnableIRQ(PORTE_IRQn,9);


thanks in advance. 
0 Kudos
Reply
10 Replies

3,913 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hello @Khaledag,

Do you use an NXP EVB?

If so, which revision, and where did you connect the sensor?

 

Have you measured the signal at PTE8?

The voltage must be at least 0.65 x VDD.

 

Can you check the all the registers in the register view?

If the port detects a rising edge, PCR_ISF of PTE8 must be set.

Please check that the interrupt is enabled/pending in NVIC.

ISER_1[31] // Set-enable

ISPR_1[31] // Set-pending

 

Best regards,

Daniel

0 Kudos
Reply

3,887 Views
Khaledag
Contributor II

Hey, 
Thanks again for you answer. 
But could you tell me where I should add these 2 lines?

  ISER_1[31] // Set-enable

  ISPR_1[31] // Set-pending

and other than that I believe the sensor has a flaw and can't trigger the interrupt and probably the initialization of the pin is successful. 

I'm still looking into it, but any other tips regarding the pin initialization and Flag set etc. would be very appreciated.

0 Kudos
Reply

3,877 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hello @Khaledag,

You need to debug it from the source.

1. Check the input signal at the PTE8 port, check the connection between PTE8 header and PTE8 pin of the MCU on the EVB. Does it reach the Vih level.

2. Does the active edge set the PORT ISF flag

3. If so, is the interrupt enabled in NVIC. You already set ISER_1[31], but since the interrupt is not active, is it pending in ISPR_1[31]?

4. If so, is the interrups masked globally, or is there a higher priority interrupt active?

 

Regards,

Daniel

 

0 Kudos
Reply

3,786 Views
Khaledag
Contributor II

Thank you for you answer and please excuse my late response. 

this is the code being used now: 

#include "device_registers.h"
#include <stdio.h>

/*! Port PTD0, bit 0: FRDM EVB output to blue LED
 */
#define PTD0  0

/*! 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->ISPR[(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)
{

	int counters = 0;

	/*!
	 * Pins definitions
	 * ===================================================
	 *
	 * Pin number        | Function
	 * ----------------- |------------------
	 * PTD0              | GPIO [BLUE LED]
	 * PTC12             | GPIO [SW2]
	 *
	 */


	/*!
	 * Initialization
	 * ===================================================
	 */

	WDOG_disable();/* Disable Watchdog in case it is not done in startup code */
  	PCC-> PCCn[PCC_PORTC_INDEX] = PCC_PCCn_CGC_MASK;

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

  	S32_NVIC_EnableIRQ(PORTC_IRQn,9);

	/*!
	 * Infinite for:
	 * ========================
	 */
		for(;;)
		{
			if (counter > 0) {
				printf("Interrupt occurred! Counter value: %d\n", counter);
				counter = 0; // Reset counter after printing
			  	}

		}
}


I can see that the PCR12 IRQC is set correctly but you're right the NVICIP31 is set to 0x00 the whole time. 
What does that mean?

0 Kudos
Reply

3,774 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hi @Khaledag,

You need to write the priority value in the 4 MSB of the IP register:

danielmartynek_0-1711616941113.png

But the IP register is not the culprit here, because by default the priority is 0, which is the highest priority.

 

Instead of writing S32_NVIC->ISPR, just monitor it.

Setting this bit makes the interrupt either pending or active.

The interrupt signal from the PORT module should set the register.

 

Regards,

Daniel

 

 

 

 

0 Kudos
Reply

3,708 Views
Khaledag
Contributor II

Sorry to bother again, 
but could you see a fault in the code? Maybe I'm not understanding correctly what you mean, sorry!

0 Kudos
Reply

3,699 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Try this:

S32_NVIC->IP[IRQn] = (Priority << 4);

 

Regards,

Daniel

0 Kudos
Reply

3,755 Views
Khaledag
Contributor II

Khaledag_0-1711623278047.png

31 is also the same.

 

0 Kudos
Reply

3,767 Views
Khaledag
Contributor II

Khaledag_0-1711618079015.png

I am monitoring the wrong ones here, right?

0 Kudos
Reply

3,909 Views
Khaledag
Contributor II

Hi, 

yes I'm using an S32K146 NXP EVB Q-144

The sensor is connected to LPSPI0 the pins are PORTB 2, 3, 4, 5

Yes I can check all the registers in the register view, I can also see that the IRQC is set to 0x9

(Please check that the interrupt is enabled/pending in NVIC.

      ISER_1[31] // Set-enable

      ISPR_1[31] // Set-pending)

So these 2 I should add to my NVIC function?

I'll try again and answer you tomorrow, I don't have the hardware right now

 

0 Kudos
Reply