How can I handle an external interrupt of GPIO PIN or UART or timer

8 posts / 0 new
Last post
gwang
Offline
Last seen:4 years 11 months ago
Joined:2014-08-07 18:27
How can I handle an external interrupt of GPIO PIN or UART or timer

HI, DIALOG
Happy new year. I have a simple but common question.
How can I hundle an external interrupt of GPIO PIN or UART ? For example, if I want to change a variable when an GPIO interrupt or UART interrupt occurs, does there have any simple soft sample? I long for your help . When I read the AN-B-026_DA14580 External wake-up mechanisms_v1.0 , it makes some sense, but has no specific samples.

TR_Dialog
Offline
Last seen:2 months 5 days ago
Staff
Joined:2014-06-30 23:52
For a fully hosted soluition,

For a fully hosted soluition, you can see the code in the following project: C:\DA1458x_SDK_3.0.6\dk_apps\keil_projects\proximity\reporter_fh.

void app_button_press_cb(void) is the callback routine when the interrupt occurs.

This callback is registered within routine app_button_enable(): wkupct_register_callback(app_button_press_cb);

Also, note that within app_button_enable routine we enable the interrupt for a given GPIO

In this case it is :

#define GPIO_BUTTON_PORT GPIO_PORT_1
#define GPIO_BUTTON_PIN GPIO_PIN_1

When you use different GPIO pin as source of interrupt the arguments passed to wkupct_enable_irq need to change accordingly.

See comments in routine wkupct_enable_irq on instructions for setting this value for different GPIO pins.

gwang
Offline
Last seen:4 years 11 months ago
Joined:2014-08-07 18:27
thanks! That info is helpful!

thanks! That info is helpful!
a new question :when I study about the function void wkupct_enable_irq(uint32_t sel_pins, uint32_t pol_pins, uint16_t events_num, uint16_t deb_time).
the param events_num ( Number of events before wakeup interrupt.) means what? What's number of events means ?

RvA
Offline
Last seen:8 hours 35 min ago
Staff
Joined:2014-02-07 14:10
Hi gwang,

Hi gwang,

the function counts the events (like a keypress for example) and wakes up the device after a certain programmed number of keypresses.

Best regards,

RvA(Dialog)

gwang
Offline
Last seen:4 years 11 months ago
Joined:2014-08-07 18:27
Hi Dialog:

Hi Dialog:
Thank you for your help. I have a new question here. I use a single IO(SPI_GPIO_PORT, SPI_DRDY_PIN ) as an external interrupt ,active LOW when an event occurs
void app_button_enable(void)
{
wkupct_register_callback(app_button_press_cb);
如果(!GPIO_GetPinStatus( SPI_GPIO_PORT, SPI_DRDY_PIN ))
wkupct_enable_irq(0x02, 0x02, 1, 0); // P0_1, polarity low , 1 event, debouncing time = 0
}

question 1: which one should I use to judge Pin's active LOW , !GPIO_GetPinStatus( ) or GPIO_GetPinStatus( )?

2. How to write the void app_button_press_cb(void) ? the system auto call the void app_button_press_cb(void) when a ext interrupt occurs?

MHv_Dialog
Offline
Last seen:1 month 2 weeks ago
Staff
Joined:2013-12-06 15:10
Hi,

Hi,

1. If you wish to verify that the pin is low you should use

如果(!GPIO_GetPinStatus( SPI_GPIO_PORT, SPI_DRDY_PIN ))

2. The call back function will be called automatically when an interrupt occurs.

overheat
Offline
Last seen:4 years 12 months ago
Joined:2014-10-10 23:34
Hello Dialog,

Hello Dialog,
I have tried this interrupt functions.

I read the definition of this function: wkupct_enable_irq (uint32_t sel_pins, uint32_t pol_pins, uint16_t events_num, uint16_t deb_time)
sel_pins Select enabled inputs. Bits 0-7 -> port 0(P00..P07), Bits 8-13 -> port 1(P10..P15),......

我认为P1_1should 0 x20; P1_2应该0 x40

But in SDK, the funtion is : wkupct_enable_irq(0x200, 0x200, 1, 10);
void app_button_enable(void)
{
wkupct_register_callback(app_button_press_cb);
如果(GPIO_GetPinStatus( GPIO_BUTTON_PORT, GPIO_BUTTON_PIN ))
wkupct_enable_irq(0x200, 0x200, 1, 10); // P1_1, polarity low , 1 event, debouncing time = 0
}

So did i misunderstand?Thanks for your kindly reply.

MT_dialog
Offline
Last seen:1 month 3 weeks ago
Staff
Joined:2015-06-08 11:34
Hi overheat,

Hi overheat,

If you set the value to 0x20 then pin P0_5 will wait to be triggered and for P1_2 the 0x400 should be set, if 0x40 then P0_6 will wait to be triggered. Please check the document UM-B-004.

Bits 0 to 7: port 0
Bits 8 to 15: port 1
Bits 16 to 23: port 2
Bits 24 to 31: port 3

Thanks MT_dialog