7 Replies Latest reply on Feb 16, 2020 7:17 AM by mahmood.hassan

    Interrupt on PIN_GIO_SPARE

    eivholt

      Hi, I'm having some problems with interrupts. I want the available pin GIO to trigger an interrupt in my code. So far I have started with bdk_blinky and been able to read the pin configured as such:

      Sys_DIO_Config(PIN_GIO_SPARE, DIO_NO_PULL | DIO_LPF_ENABLE | DIO_MODE_GPIO_IN_0);

      I am trying to understand the API on how to configure interrupts. I have tried this:

       

      Sys_DIO_IntConfig(0,

      DIO_DEBOUNCE_ENABLE |

      DIO_SRC_DIO_0 |

      DIO_EVENT_HIGH_LEVEL,

      DIO_DEBOUNCE_SLOWCLK_DIV32,

      0);

       

      experimenting with the parameters. I have implemented:

       

      void DIO0_IRQHandler(void){

      LED_On(LED_BLUE);

      }

       

      with breakpoint. It never hits.

       

      Can anyone explain what index and DIO_SRC_DIO_* means in this context and what I can use? Should I use another library?

      I tried to modify the bdk_button to use the PIN_GIO_SPARE pin instead of button0, but to no avail.

        • Re: Interrupt on PIN_GIO_SPARE
          shabaz

          Hi Eivind,

           

          I have not checked the documentation, but I know how I would find out, so I can point you in the right direction.

          The DIO_SRC_DIO_0 is most likely (I'm guessing) indicating which pin you wish to use for the interrupt. The RSL10 chip is unusual (in a good way) in that any pin can be used for any feature, as far as I know (I could be wrong). Anyway, if you want to be certain how to use that API call, just hit F3 in the IDE, and it will find the definition and it will be described.

          To me it doesn't seem any other library needs to be used. You're currently using C and a low-level API which should meet your needs for things like I/O and interrupts.

          It looks very straightforward. As for breakpoints, I have not used them with the RSL10. Maybe you're running in Release mode instead of Debug mode. Anyway, you could step through if you really wanted to. Alternatively as a workaround, you could just light an LED to test how far in the code you have got.

          EDIT: One more thing, perhaps interrupts need to be enabled globally too. Usually (at least with other microcontrollers), once you have configured up individual interrupts, there's a master-control to enable or disable that configuration.

          1 of 1 people found this helpful
            • Re: Interrupt on PIN_GIO_SPARE
              eivholt

              For anyone joining in you can check out the relevant API documentation here. I came over this code and plan to explore the function DIO_SRC( to see if it performs any mapping magic. I'll also post the complete code. I did not perform any masking, disabling or clearing of the interrupt registers, as I thought that was only relevant if using more than one interrupt. Maybe this is the issue.

               

              /* Mask all interrupts */

                  __set_PRIMASK(PRIMASK_DISABLE_INTERRUPTS);

               

                  /* Disable all existing interrupts, clearing all pending source */

                  Sys_NVIC_DisableAllInt();

                  Sys_NVIC_ClearAllPendingInt();

              The documentation isn't very informative on when this has to be done, so any explanation would be welcome.

              I have interrupt handlers on DIO0 through DIO3, and they lit leds and have breakpoints.

               

              I will investigate the suggestion of globally enabling interrupts, thanks.

              • Re: Interrupt on PIN_GIO_SPARE
                mahmood.hassan

                Yes it is true that any GPIO can be used for any digital function.

                DIO-0 to DIO-3 are analog inputs and again any of these pin can be connected with any channel of ADC.

                 

                The DIO_SRC_DIO_0 is most likely (I'm guessing) indicating which pin you wish to use for the interrupt. The RSL10 chip is unusual (in a good way) in that any pin can be used for any feature, as far as I know (I could be wrong). Anyway, if you want to be certain how to use that API call, just hit F3 in the IDE, and it will find the definition and it will be described.

              • Re: Interrupt on PIN_GIO_SPARE
                eivholt

                I believe I have found a likely explanation for the interrupt handlers not triggering; I did not realize I had to declare the handler like this:

                extern void DIO0_IRQHandler(void);

                My implementation does not declare the override in the right scope and the default implementations are probably still being run. At least it's worth checking out. Will post an update.

                • Re: Interrupt on PIN_GIO_SPARE
                  eivholt

                  I confirmed that my issue was due to missing this before configuring the interrupt:

                   

                  /* Mask all interrupts */

                  __set_PRIMASK(PRIMASK_DISABLE_INTERRUPTS);

                   

                  /* Disable all existing interrupts, clearing all pending source */

                  Sys_NVIC_DisableAllInt();

                  Sys_NVIC_ClearAllPendingInt();

                   

                  And after that:

                  /* Enable interrupts */

                  NVIC_EnableIRQ(DIO0_IRQn);

                  NVIC_EnableIRQ(I2C_IRQn);

                   

                  /* Unmask all interrupts */

                  __set_PRIMASK(PRIMASK_ENABLE_INTERRUPTS);

                   

                  So I am wondering if omiting this leads to the interrupt configuration being overridden. Any one able to explain?

                  I am happy to be able to proceed with interrupts now, I hope someone else finds it helpful.

                    • Re: Interrupt on PIN_GIO_SPARE
                      mahmood.hassan

                      Simplified solution.

                      NVIC_DisableIRQ(DIO0_IRQn);
                      Sys_DIO_Config(PIN_GIO_SPARE, DIO_NO_PULL | DIO_LPF_ENABLE | DIO_MODE_GPIO_IN_0);
                      Sys_DIO_IntConfig(0, PIN_GIO_SPARE | DIO_EVENT_FALLING_EDGE | DIO_DEBOUNCE_ENABLE , DIO_DEBOUNCE_SLOWCLK_DIV32, 0);
                      NVIC_ClearPendingIRQ(DIO0_IRQn);
                      NVIC_EnableIRQ(DIO0_IRQn);
                      

                       

                      Interrupt handler function

                      void DIO0_IRQHandler(void)
                      {
                          LED_Toggle(PIN_LED_RED);
                      }
                      

                       

                      No need to disable all the interrupts. You can also use DIO1_IRQn, DIO2_IRQn or DIO3_IRQn with PIN_GIO_SPARE.

                       

                      * External pull-up resistor is required because we will be detecting falling edge and GPIO is configured without any pull up/down setting.

                      1 of 1 people found this helpful