External interrupts

mikroC, mikroBasic and mikroPascal for PRO ARM® MCUs, supporting STM32, Tiva, Kinetis, & CEC devices
Post Reply
Author
Message
paddywac
Posts: 10
Joined: 17 Nov 2015 13:28

External interrupts

#1 Post by paddywac » 24 Nov 2019 22:38

Hi,

I'm trying to get an external interrupt to work on port PB5. Interrupt on the rising edge. I can see the IO pin going high on a scope, and if I put some code in to detect PB5 going high it works. I just can't get the interrupt routine to work.

Here's the code:

I can see the EXTI_PR bit go high in a watch windows, but the interrupt won't fire. Any ideas gratefully received.

Thanks in advance....

void ExtInt() iv IVT_INT_EXTI2 ics ICS_AUTO
{
EXTI_PR.B5 = 1; // clear flag
AccDataReady = 1;
}


void main()
{

/* Variables to control the LEDs. */
uint16_t LedBrightness[LEDBRT_NUMLEVELS];
boolean_t RampUpBrightness = 1;
boolean_t RampLEDsUp = 1;
uint8_t PushButtonCounter = 0;
uint8_t LEDCycleCounter = 0;
uint8_t BrightnessPointer = 2;
uint8_t LEDState = LEDSTATE_OFF;

/* Declare variables for the accelerometer. */
volatile int16_t accX, accY, accZ;
volatile uint8_t AccWhoAmI = 0;
boolean_t Last_INT = 0;

/* Clear global variables. */
AccDataReady=0;

ConfigureIO();

RCC_APB2ENR = 9; // Enable clock for alternate pin functions
AFIO_EXTICR2 = 0x010; // PB5 as External interrupt
EXTI_RTSR = 0x20; // Set interrupt on Rising edge
EXTI_IMR |= 0x20; // Set mask
NVIC_IntEnable(IVT_INT_EXTI2); // Enable External interrupt

EnableInterrupts(); // Enables the processor interrupt.

AccWhoAmI = Acc_readWhoAmI();

while(1)
{
/* Check for accelerometer data. */
if (AccDataReady == 1)
{
Acc_ReadAccData(&accX, &accY, &accZ); // 250us
AccDataReady = 0;
}
}
}

User avatar
jovana.medakovic
mikroElektronika team
Posts: 986
Joined: 18 Dec 2018 10:36

Re: External interrupts

#2 Post by jovana.medakovic » 25 Nov 2019 12:53

Hello,

Can you tell me which MCU you are using, so I can try to test the external interrupt?
Can you zip and send me your project?
Can you tell me which development board you are using?

Kind regards,
Jovana

paddywac
Posts: 10
Joined: 17 Nov 2015 13:28

Re: External interrupts

#3 Post by paddywac » 25 Nov 2019 16:23

Hi Jovana, thanks for replying to my post. Please find attached the project zipped up. I am doing the development on my own hardware, but this bit is a LIS3DSH accelerometer connected to PB5, with a 82K pull up. I can see the INT pin activity on a scope. Also, if I put some code into the micro to detect the INT pulse, it works. But the interrupt doesn't fire.

I am using an STM32F105RCT6. I do have a EasyMx Pro v7 development board with the STM32F107 processor and the Accel2 click board that has the LIS3DSH accelerometer on it, so we could use that as a reference platform. If you can get it working on that I'm sure it will port across to my hardware!

At the moment in my project I have the clock set APB2 clock set to run at 64MHz, and I'm wondering if that is too quick for the edge of the INT signal from the LIS3DSH? I'm going to try slowing it down.

Thanks again for your help.

Pete N.
Attachments
BRMv1.zip
Project zipped up.
(281.53 KiB) Downloaded 112 times

paddywac
Posts: 10
Joined: 17 Nov 2015 13:28

Re: External interrupts

#4 Post by paddywac » 26 Nov 2019 21:51

I tried slowing down the clock to the IO pins (APB2), but this didn't help.

Thanks
Pete N.

User avatar
jovana.medakovic
mikroElektronika team
Posts: 986
Joined: 18 Dec 2018 10:36

Re: External interrupts

#5 Post by jovana.medakovic » 27 Nov 2019 16:17

Hello,

In the attachment, you can find an example for an external interrupt which I tested and it works fine.

If you want to use PB5 for interrupt, you need to use IVT_INT_EXTI9_5, not IVT_INT_EXTI2. In the reference manual you can read about that:
https://www.st.com/content/ccc/resource ... 171190.pdf

Run this example and let me know if it works.

Kind regards,
Jovana
Attachments
External Interrupt.zip
(148.05 KiB) Downloaded 146 times

paddywac
Posts: 10
Joined: 17 Nov 2015 13:28

Re: External interrupts

#6 Post by paddywac » 27 Nov 2019 21:19

That works, fantastic. Basically I had the interrupt vector wrong.

Thanks again for the great support :-)

Pete

User avatar
jovana.medakovic
mikroElektronika team
Posts: 986
Joined: 18 Dec 2018 10:36

Re: External interrupts

#7 Post by jovana.medakovic » 28 Nov 2019 15:04

Hi,

You're welcome.
I'm glad that your problem is solved.

Kind regards,
Jovana

Post Reply

Return to “ARM PRO Compilers”