Trying to make sense of mapping external interrupts to a single pin

General discussion on mikroC PRO for ARM.
Post Reply
Author
Message
CoachAllenXPX
Posts: 12
Joined: 15 May 2020 00:49

Trying to make sense of mapping external interrupts to a single pin

#1 Post by CoachAllenXPX » 18 Dec 2022 05:12

Greetings,

STM32F407ZG on a Fusion for ARM v8 development board
MikroC Pro for Arm v6.2.0

I am once again taking this Fusion for Arm v8 board out of the box and trying to use this. Every time I do, I just get frustrated and regret ever buying this and/or anything from this company. The idea was to really have a great tool to learn ARM and prototype. ME seemed like such an awesome thing. The boards are gorgeous and I love how everything is made to make development easy. UNTIL YOU PLUG IT IN AND HAVE TO WRITE ANY SORT OF YOUR OWN CODE FOR IT :oops: :evil: :twisted:.

I have been able to run some of the example code files and that's all fine but I actually wanted to learn how to use this product. I box it up and wait a year to see if ME ever gets documentation right. Sadly not yet. Why don't they just give up and let us use their product with something like Cube IDE so when we search for how to make something work on google, we can follow actual examples that aren't some imposed proprietary **** like the MikroC for ARM. If you aren't going to document well, don't make it so damned hard to use elsewhere.

So what I am trying to iterate through is how use an interrupt on a GPIO like PA0 as an example. When PAO is pressed I would like to use an ISR to handle that press to change the value of a variable. This would allow me to continue on my journey to try other things and worked with the board. The Interrupt Assistant Tool is a major letdown. I assumed I would be able to follow a series of prompts to set a rising edge interrupt on a GPIO and code blocks would be generated to make that happen. Nope!!! Just a lousy ISR shell is written and you can't even make sense of whether or not you picked the correct option. Don't even try google because the code expectations within MikroC are nowhere near they STM datasheets or application notes.

Lets start with the example code

Code: Select all


  SYSCFGEN_bit = 1;                    // Enable clock for alternate pin functions
  SYSCFG_EXTICR3 = 0x00000300;         // Map external interrupt on PD10
  EXTI_RTSR = 0x00000000;              // Set interrupt on Rising edge (none)
  EXTI_FTSR = 0x00000400;              // Set Interrupt on Falling edge (PD10)
  EXTI_IMR |= 0x00000400;              // Set mask
  NVIC_IntEnable(IVT_INT_EXTI15_10);   // Enable External interrupt

Where would you even look to know what the long hex values should be in you wanted to target PA0 rather that PD10?

What if I put in

Code: Select all

EXTI_FTSR = 0x00000100;
instead of

Code: Select all

EXTI_FTSR = 0x00000400;
How do I even know where to look to find different values? It's not in the documentation built into MikroC nor do they have any documentation anywhere on there website! This is the **** that just pisses me right off. You find a really cool solution to prototype dev boards and are met with a company that doesn't really have a fully baked solution. They will sell you $1K worth and hardware and compiler license and leave you hanging. I wish like hell I could just search the manual (that doesn't exist), the forums (usually dead ends that only the staff ever respond to with a short answer and no user community that responds well to each other, google (tons of documentation and code samples for the real STM/ARM code not MikroC). Does anyone actually buy from ME and succeed?

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: Trying to make sense of mapping external interrupts to a single pin

#2 Post by filip » 19 Dec 2022 09:14

Hi,
I have been able to run some of the example code files and that's all fine but I actually wanted to learn how to use this product. I box it up and wait a year to see if ME ever gets documentation right. Sadly not yet. Why don't they just give up and let us use their product with something like Cube IDE so when we search for how to make something work on google, we can follow actual examples that aren't some imposed proprietary **** like the MikroC for ARM. If you aren't going to document well, don't make it so damned hard to use elsewhere.
I apologize if you feel this way, can you tell me which documentation do you find lacking ? There is a comprehensive help file for the mikroC PRO for ARM compiler, the Fusion board and the on-board CODEGRIP debugger.
So what I am trying to iterate through is how use an interrupt on a GPIO like PA0 as an example. When PAO is pressed I would like to use an ISR to handle that press to change the value of a variable. This would allow me to continue on my journey to try other things and worked with the board. The Interrupt Assistant Tool is a major letdown. I assumed I would be able to follow a series of prompts to set a rising edge interrupt on a GPIO and code blocks would be generated to make that happen. Nope!!! Just a lousy ISR shell is written and you can't even make sense of whether or not you picked the correct option. Don't even try google because the code expectations within MikroC are nowhere near they STM datasheets or application notes.
The interrupt assistant only generated interrupt routine declaration, it is not a code configurator that lets you choose options in a wizard form.

You can have a look at the External Interrupt example that is located in the installation folder of the compiler :
\mikroC PRO for ARM\Examples\ST\Internal MCU modules\STM32F407VG\External Interrupt\

There you will see how we implemented this, and if you want to use this for another pin, you can write a similar code, but I suggest that you consult the datasheet for specific information.

Regards,
Filip.

CoachAllenXPX
Posts: 12
Joined: 15 May 2020 00:49

Re: Trying to make sense of mapping external interrupts to a single pin

#3 Post by CoachAllenXPX » 29 Dec 2022 21:55

Typical and expected response,

The documentation found using the Help Menu within the IDE does in fact have some guidance on interrupts. Also I have found the example file located within the path you specified prior to your response. If you carefully examine my original post, you'd find two code snippets where I am pointing out some register settings. I examined the datasheets for the STM32F407ZG and I cannot seem to locate the information on what was included in my original posts.

Code: Select all

EXTI_RTSR = 0x00000000;              // Set interrupt on Rising edge (none)
// *************LIKE WHERE THE HELL IS THIS DECLARED***********
EXTI_FTSR = 0x00000400;              // Set Interrupt on Falling edge (PD10)

// WHAT WOULD HAPPEN IF I PUT IN A VALUE LIKE 0x00001000???????????????????
// Where can I find more information about what values to set for PA0 or PB3? Rising and Falling?
Unfortunately, I find the MikroE as well as the community do not provide support for this ecosystem, especially for those like myself who bought it to escape the limits of Arduino and build upon a robust prototyping system such as the Fusion for ARMv8. It may be great if people can buy this product and never need assistance, but in my experience, this has not been the case.

Thomas.Pahl@t-online.de
Posts: 158
Joined: 24 May 2008 15:55
Location: Germany

Re: Trying to make sense of mapping external interrupts to a single pin

#4 Post by Thomas.Pahl@t-online.de » 31 Dec 2022 13:44

The only information needed for this is the reference manual, chapter 12 'interrupts and events' page 371.


CoachAllenXPX
Posts: 12
Joined: 15 May 2020 00:49

Re: Trying to make sense of mapping external interrupts to a single pin

#6 Post by CoachAllenXPX » 05 Jan 2023 03:46

@AntiMember @Thomas.Pahl@t-online.de

Thanks for taking some time to drop in and post on this topic! That almost never happens.

So I read through the docs in each of the recommended links and I feel like I am starting to see a little bit of light at the end of the tunnel. Still confused on how to set bits in the registers though. I have some experience with 8 bit MCUs (obviously, with my rant on Arduino).

Here's a little bit of what I was able to put together.

Code: Select all

SYSCFG_EXTICR3 = 0x00000300;
Should change to:

Code: Select all

SYSCFG_EXTICR1 = 0x????????;
Now the bit registers for PAx are the first four bits in that register (EXTI0). According to the datasheet and reference manual, If I left the values unset (0000) this would affect the PAx pins. So would this be the correct way to set the interrupts for PA0?

Code: Select all

SYSCFG_EXTICR1 = 0x0000 0000;
Getting back to what is confusing me is the value being passed. I'm stuck in this mindset that I could pass a hexadecimal value or even a binary value and use bitwise operators to shift in bits. So when I see:

Code: Select all

SYSCFG_EXTICR3 = 0x0000 0300; // Map external interrupt on PD10
I am absolutely thrown off. I would normally look at this like a hexadecimal. But how? When I look at the reference manuals I see that I could pass 0x0000 0011 to get something on PDx. So where does 0x0000 0300 make any sense? Is this a super big 32 bit hex that decodes to binary? How does this specifically hit PD10 as the interrupt pin? I hope my continued questions make sense...

Cheers,

AntiMember
Posts: 136
Joined: 02 Jan 2020 19:00

Re: Trying to make sense of mapping external interrupts to a single pin

#7 Post by AntiMember » 05 Jan 2023 08:49

EXTICR1 - EXTICR4 registers contain 4 bits each for EXTI0 - EXTI15.
EXTI0 = pin0.......EXTI15 = pin15.
SYSCFG_EXTICR1 = 0x0000 0003; = PD0.
SYSCFG_EXTICR1 = 0x0000 0030; = PD1.
SYSCFG_EXTICRx = 0x0000 0000; = PAx.
And we must remember that interrupt lines are distributed:
EXTI Line0 interrupt
EXTI Line1 interrupt
EXTI Line2 interrupt
EXTI Line3 interrupt
EXTI Line4 interrupt
EXTI Line[9:5] interrupts
EXTI Line[15:10] interrupts
Therefore, for the high bits, it is necessary to check which bit the interrupt was on when entering the interrupt.
Here is an example from SPL (I don't use mikroe)
void EXTI15_10_IRQHandler(void)
{
if (EXTI_GetITStatus(EXTI_Line10) != RESET)
{
user code
}
}

CoachAllenXPX
Posts: 12
Joined: 15 May 2020 00:49

Re: Trying to make sense of mapping external interrupts to a single pin

#8 Post by CoachAllenXPX » 05 Jan 2023 17:03

This is insightful for sure. The concept of moving the value over makes sense according to what I saw in the reference manuals. However why are you passing "0x0000 0003"? As I understand it, that is the binary equivalent of "0b11". And in my original posting the code example used a value of "0x0000 0400". I need help understanding why those values are used. I think it might have something to do with how each of the 32 bit fields are condensed into a smaller HEX. For example, instead of writing out:

Code: Select all

0b0000 1100 1010 0000 0000 0000 1111 00000
to set each of the 32 bits . You could pass in the HEX:

Code: Select all

0x0000 03E0
I know these two code examples do not match but I am trying to see whether or not my understanding is correct.

AntiMember
Posts: 136
Joined: 02 Jan 2020 19:00

Re: Trying to make sense of mapping external interrupts to a single pin

#9 Post by AntiMember » 05 Jan 2023 19:17

CoachAllenXPX wrote:
05 Jan 2023 17:03
And in my original posting the code example used a value of "0x0000 0400".
CoachAllenXPX wrote:
18 Dec 2022 05:12
SYSCFG_EXTICR3 = 0x00000300; // Map external interrupt on PD10

Code: Select all

HEX bit  3  2  1  0
value    8  4  2  1
0b0011 = 2+1 = 0x3
0b1001 = 8+1 = 0x9
0b1111 = 0xF

CoachAllenXPX
Posts: 12
Joined: 15 May 2020 00:49

Re: Trying to make sense of mapping external interrupts to a single pin

#10 Post by CoachAllenXPX » 05 Jan 2023 22:59

32 Bit Coversion tool.png
32 Bit Coversion tool.png (7.42 KiB) Viewed 1404 times
I made this little tool in Google Sheets today right after I replied to your latest. So I can see there what happens with the value of 3. Each of the EXTIx fields have 4 r/w bits so why not just use a hex value of F (1111)? Why use 3 (0011)? By the way I am super grateful for your continued assistance.

CoachAllenXPX
Posts: 12
Joined: 15 May 2020 00:49

Re: Trying to make sense of mapping external interrupts to a single pin

#11 Post by CoachAllenXPX » 05 Jan 2023 23:09

SYSCFG.png
SYSCFG.png (53.43 KiB) Viewed 1404 times
So here's a little snippet from the PDF and I have overlaid to the hex value as discussed over the registers. So we only set half of the field to "1's" if using 0x0000 0300. Why is that?

CoachAllenXPX
Posts: 12
Joined: 15 May 2020 00:49

Re: Trying to make sense of mapping external interrupts to a single pin

#12 Post by CoachAllenXPX » 05 Jan 2023 23:29

Oh my goodness!!! I think I just got it!!!

If you wanted to hit PA0 as the interrupt, you would send 0x0000 0000 But if you wanted to hit PB0 you would send 0x0000 0001

Time for a breakout:

SYSCFG_EXTICR1 -- All in the EXTI0
PA0 = 0x0000 0000
PB0 = 0x0000 0001
PC0 = 0x0000 0002

SYSCFG_EXTICR3 -- In the EXTI6
PA6 = 0x0000 0000
PD6 = 0x0000 0300

Does this seem correct?

AntiMember
Posts: 136
Joined: 02 Jan 2020 19:00

Re: Trying to make sense of mapping external interrupts to a single pin

#13 Post by AntiMember » 06 Jan 2023 07:00

CoachAllenXPX wrote:
05 Jan 2023 23:29
SYSCFG_EXTICR3 -- In the EXTI6
PA6 = 0x0000 0000
PD6 = 0x0000 0300

Does this seem correct?
SYSCFG_EXTICR2 -- In the EXTI6
Outcome...

Code: Select all

  SYSCFGEN_bit = 1;                    // Enable clock for alternate pin functions
  SYSCFG_EXTICR1 = 0x00000000;         // Map external interrupt on PA0
  EXTI_RTSR = 0x00000000;              // Set interrupt on Rising edge (none)
  EXTI_FTSR = 0x00000001;              // Set Interrupt on Falling edge (PA0)
  EXTI_IMR |= 0x00000001;              // Set mask (PA0)
  NVIC_IntEnable(IVT_INT_EXTI0);   // Enable External interrupt

Code: Select all

  SYSCFGEN_bit = 1;                    // Enable clock for alternate pin functions
  SYSCFG_EXTICR2 = 0x00000300;         // Map external interrupt on PD6
  EXTI_RTSR = 0x00000000;              // Set interrupt on Rising edge (none)
  EXTI_FTSR = 0x00000040;              // Set Interrupt on Falling edge (PD6)
  EXTI_IMR |= 0x00000040;              // Set mask (PD6)
  NVIC_IntEnable(IVT_INT_EXTI9_5);   // Enable External interrupt

CoachAllenXPX
Posts: 12
Joined: 15 May 2020 00:49

Re: Trying to make sense of mapping external interrupts to a single pin

#14 Post by CoachAllenXPX » 06 Jan 2023 16:53

I was able to begin a brand new project from scratch and write line by line each statement needed to execute the interrupt! This is the first time in nearly 3 years I have been able to complete a task with the development ecosystem from MikroE. It is very trivial to many but to me it's a big deal as I have always wanted to use this device to learn with. I want to really say thank you for taking the time to drop in consistently to assist! Without you I would still be struggling to grasp the concept.

To really make sure I understand external interrupts, I used various values to use any of the buttons on the left side. This meant that I had to double check the reference manuals and alter the hex values to target the correct button. I think I have it down pretty good now. The next step for me is to build another process like sequence random LEDs and use the interrupt concurrently and perhaps use the interrupt to alter a variable which can be used to change the direction of the sequence. This small victory has reawakened my interest in this board. THANKS SO MUCH AntiMember!!!

AntiMember
Posts: 136
Joined: 02 Jan 2020 19:00

Re: Trying to make sense of mapping external interrupts to a single pin

#15 Post by AntiMember » 06 Jan 2023 19:56

@CoachAllenXPX
Good luck!

Post Reply

Return to “mikroC PRO for ARM General”