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;
}
}
}
External interrupts
- jovana.medakovic
- mikroElektronika team
- Posts: 986
- Joined: 18 Dec 2018 10:36
Re: External interrupts
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
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
Re: External interrupts
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.
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
Re: External interrupts
I tried slowing down the clock to the IO pins (APB2), but this didn't help.
Thanks
Pete N.
Thanks
Pete N.
- jovana.medakovic
- mikroElektronika team
- Posts: 986
- Joined: 18 Dec 2018 10:36
Re: External interrupts
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
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
Re: External interrupts
That works, fantastic. Basically I had the interrupt vector wrong.
Thanks again for the great support
Pete
Thanks again for the great support
Pete
- jovana.medakovic
- mikroElektronika team
- Posts: 986
- Joined: 18 Dec 2018 10:36
Re: External interrupts
Hi,
You're welcome.
I'm glad that your problem is solved.
Kind regards,
Jovana
You're welcome.
I'm glad that your problem is solved.
Kind regards,
Jovana