8 Replies Latest reply on Sep 24, 2015 7:19 AM by userc_16079 Branched to a new discussion.

    Return value of gpio_getPinInput

      Hi

       

      The return value of gpio_getPinInput is BYTE.

      In short, is the range of the return value from 0 to 255 by default like Analog Input, in't it?

      How can I use GPIO as Digital Input?

      I want to get the return value of a GPIO as HIGH and LOW.

       

      Then, can I use a GPIO pin as interrupt pin and digital input?

      I configured like following:

      ------------------------------------------------

      #define GPIO_PIN 25

      #define GPIO_SETTING GPIO_PIN GPIO_INPUT | GPIO_INIT_LOW | GPIO_INT | GPIO_INTERRUPT_ENABLE

       

      gpio_configurePin(GPIO_PIN/16, GPIO_PIN%16, GPIO_EN_INT_LEVEL_HIGH | GPIO_PULL_DOWN | GPIO_INPUT_ENABLE, GPIO_PIN_OUTPUT_LOW);

      -------------------------------------------------

      After I make my board enter Deep Sleep, I use this pin to wake it up.

      I want my board to enter Deep Sleep with the exception that the state of GPIO_PIN is HIGH.

      In short, I want to implement like following:

      While GPIO_PIN is HIGH, my board works.

      While GPIO_PIN is LOW, my board is Deep Sleep mode.

      How should I do for realizing this function?

       

      By the way,

      I have been using GPIO_PIN(25) as a interrupt pin to wake my board up.

      If the current setting, while my borad works, the GPIO interruption happens every time (every 6.5ms)?

      Should I use GPIO_EN_INT_RISING_EDGE?

      Is RISING_EDGE robust to noise?

       

      Best regards

        • 1. Re: Return value of gpio_getPinInput

          Hello.

           

          Trying looking at this post.

          Help setting up interrupt on GPIO

           

          Let us know if this helps.

           

          James

          • 2. Re: Return value of gpio_getPinInput
            JacobT_81

            gpio_getPinInput will return 0 or 1. Analog inputs are only enabled by activation of the ADC and by use of certain pins.

             

            To set up an interrupt (rising):

                         gpio_configurePin(GPIO_PIN/16, GPIO_PIN%16, GPIO_EN_INT_RISING_EDGE, GPIO_PIN_OUTPUT_LOW);


            To set up an interrupt on the falling edge:

                          gpio_configurePin(GPIO_PIN/16, GPIO_PIN%16, GPIO_EN_INT_FALLING_EDGE, GPIO_PIN_OUTPUT_LOW);

             

            When going to sleep you want to register for an interrupt on the rising edge. When waking up you want to register an interrupt on the falling edge. As a result you'll need two different interrupt handlers for wake up and sleep.


            With this there shouldn't be any need to use the pin as in input since you always know the state of the pin via interrupt: it's always high while you're awake and low while you're in deep sleep.

             

            In my experience the interrupts are not susceptible to noise.

             

            Jacob


            • 3. Re: Return value of gpio_getPinInput

              Thank you for your response, userc_19497 and JacobT_81.

               

              I read this thread: Help setting up interrupt on GPIO.

              Namely, I have to use a variable to realize Deep Sleep and Wake up function by using only one pin?

              For example, before entering Deep Sleep, a variable (e.g. BOOL sleep_flag) is assigned FALSE(0).

              When my board wakes up, sleep_flag is assigned TRUE(1);

              Otherwise, Is it possible to assign two different interrupt handlers to one GPIO pin?

              For instance, when rising_edge interruption fires, waking_up_interrupt_handler starts.

              When falling_edge interruption fires, deep_sleep_interrupt_handler starts.

              Can I implement two different functions as above?

               

               

              >gpio_getPinInput will return 0 or 1. Analog inputs are only enabled by activation of the ADC and by use of certain pins.

              I see. Please let me confirm that return value of gpio_getPinInput is 0 or 1, not 0 or 255, right?

               

              >When going to sleep you want to register for an interrupt on the rising edge. When waking up you want to register an interrupt on the falling edge. As a result you'll need two different interrupt handlers for wake up and sleep.

              Is it possible to use one pin for GPIO interruption of both falling edge and rising edage?

              In short, is it possible to set two different interrupt handlers to one pin like GPIO_PIN(P25)?

              I want to implement a function such as you say. I want to use P25 as GPIO interruption for triggers to make deep sleep (falling edge) and wake up (rising edge) work.

               

              Best regards

              • 4. Re: Return value of gpio_getPinInput
                JacobT_81

                Hi userc_16079,

                 

                You can be an interrupt on both the rising and falling edge, but in your case it's undesirable since there exists the possibility for the system to become un-synchronized if a small error occurs.

                 

                The best way to go about it is to register for an interrupt on the rising edge right when you put the device to sleep, and then register for an interrupt on the falling edge, right as you wake up. This way the device goes to sleep on the falling edge and wakes on the rising edge, as you described in your initial post.

                 

                void called_when_woken_up (void* parameter, UINT8 arg){

                     //register for interrupt on falling edge

                    {

                    UINT16 masks[3] = {0,(1<<9) , 0};

                    gpio_registerForInterrupt(masks, called_when_going_to_sleep, 0);

                    }

                    gpio_configurePin(25/16, 25%16, GPIO_EN_INT_FALLING_EDGE, GPIO_PIN_OUTPUT_LOW);

                 

                }

                 

                void called_when_going_to_sleep (void* parameter, UINT8 arg){

                     //register for interrupt on rising edge

                 

                    {

                    UINT16 masks[3] = {0, (1<<9) , 0};

                    gpio_registerForInterrupt(masks, called_when_woken_up, 0);

                    }

                    gpio_configurePin(25/16, 25%16, GPIO_EN_INT_RISING_EDGE, GPIO_PIN_OUTPUT_LOW);

                }

                 

                Additionally, getPinInput() does return a 1 or 0.

                 

                Jacob

                • 5. Re: Return value of gpio_getPinInput

                  Hi JacobT_81

                   

                  Thank you for very kind explanation.

                   

                  >The best way to go about it is to register for an interrupt on the rising edge right when you put the device to sleep, and then register for an interrupt on the falling edge, right as you wake up. This way the device goes to sleep on the falling edge and wakes on the rising edge, as you described in your initial post.

                   

                  I wrote as you say.

                  However, there is a case not to be able to enter Deep Sleep mode at P0, P4, P13 on the tag3 reference board.

                  I connected them and GND through 10k Ohm, the problem sometimes happens.

                  Do you know the reason why this happens?

                  Are there any differences from GPIOs? Can't P0, P4 and P13 be used as GPIO interruption pin?

                   

                  Best regards

                  • 6. Re: Return value of gpio_getPinInput
                    MichaelF_56

                    -->Can't P0, P4 and P13 be used as GPIO interruption pin?


                    Essentially, P0 is part of a keyscan matrix (an artifact from the core HID design 20730 that these 2073X follow-on chips are based on).


                    As such, the part via P0 is looking for a keypress which is a low (i.e. ground).  Trying to use this GPIO in an application can lead to trouble, so it is advised to pull P0 high. Then, before entering deep sleep, the app must input and output disable P0 using gpio_configurePin(0,0,GPIO_INPUT_DISABLE | GPIO_OUTPUT_DISABLE,0);


                    For instance, if the application tried to use P0 to try to turn off the device. The device would start to go into deep-sleep, and then if this occurred at the same time as the keyscan operation (cannot be disabled), the part would detect this as a keypress and would abort the sleep operation.

                    Again, pull P0 high and then, before entering deep sleep, input and output disable P0 using gpio_configurePin(0,0,GPIO_INPUT_DISABLE | GPIO_OUTPUT_DISABLE,0).

                    • 7. Re: Return value of gpio_getPinInput
                      JacobT_81

                      userc_16079

                       

                      I just tested and can confirm that MichaelF_56's suggestion is correct. All attempts to enter deep sleep fail as a result of leaving P0 floating. Please physically pull this pin high and in your code call gpio_configurePin(0,0,0,0) to disable it.

                       

                      I attached my code which puts the device into deep sleep immediately on creation and wakes it via rising edge interrupt on P4.

                       

                      Jacob

                      1 of 1 people found this helpful
                      • 8. Re: Return value of gpio_getPinInput

                        Hi, JacobT_81

                         

                        Thank you for your code.

                        In your code, where is the definition of bleprofile_abortHidoff()?

                        How does it work?

                         

                        Best regards