PIN ACTIVATION ON STATES????

4 posts / 0 new
Last post
jorge
Offline
Last seen:4 years 2 months ago
Joined:2016-01-25 14:20
PIN ACTIVATION ON STATES????

Hello.

im kind of new with this bluetooth, im trying to set a pin low when its connected and when its disconnected set it on high, so i want it to do it by asking for the state machine, how can i do that?

this is what i have but is not working.
int state;
int state2;

state=ke_state_get(APP_CONNECTED);

while (state==true)
{
GPIO_ConfigurePin( GPIO_PORT_0, GPIO_PIN_6, OUTPUT, PID_GPIO,true);
GPIO_SetInactive( GPIO_PORT_0, GPIO_PIN_6 );

}
state2=ke_state_get( APP_CONNECTABLE);
while (state2==true)
{

GPIO_ConfigurePin( GPIO_PORT_0, GPIO_PIN_6, OUTPUT, PID_GPIO,false);
GPIO_SetActive (GPIO_PORT_0 GPIO_PIN_6);
}

}

thnx.

Device:
slava
Offline
Last seen:3 years 6 months ago
Joined:2015-04-28 10:35
If you sdk is 5 you need to

If you sdk is 5 you need to put gpio initialization into function set_pad_functions in user_periph_setup.c.
Then see user_app_callbacks structure in user_callback_config.h.

static const struct app_callbacks user_app_callbacks = {
.app_on_connection = default_app_on_connection,
.app_on_disconnect = default_app_on_disconnect,
.app_on_update_params_rejected = NULL,
.app_on_update_params_complete = NULL,
.app_on_set_dev_config_complete = default_app_on_set_dev_config_complete,
.app_on_adv_undirect_complete = app_advertise_complete,
.app_on_adv_direct_complete = NULL,
.app_on_db_init_complete = default_app_on_db_init_complete,
.app_on_scanning_completed = NULL,
.app_on_adv_report_ind = NULL,
.app_on_pairing_request = default_app_on_pairing_request,
.app_on_tk_exch_nomitm = default_app_on_tk_exch_nomitm,
.app_on_irk_exch = NULL,
.app_on_csrk_exch = default_app_on_csrk_exch,
.app_on_ltk_exch = default_app_on_ltk_exch,
.app_on_pairing_succeded = NULL,
.app_on_encrypt_ind = NULL,
.app_on_mitm_passcode_req = NULL,
.app_on_encrypt_req_ind = default_app_on_encrypt_req_ind,
};

default_app_on_connection and default_app_on_disconnect it is what you need.

Add GPIO_SetInactive( GPIO_PORT_0, GPIO_PIN_6 ) inside default_app_on_connection
and GPIO_SetActive(GPIO_PORT_0, GPIO_PIN_6) inside default_app_on_disconnect

MT_dialog
Offline
Last seen:2 months 5 days ago
Staff
Joined:2015-06-08 11:34
Hi jorge,

Hi jorge,

The ke_state_get gets a task as a parameter (TASK_APP) and returns the task state (APP_CONNECTED, APP_SECURITY, etc), you can configure the functionality of your pins at the user_periph_setup.c and use only the GPIO_SetActive and Inactive to configure the output of the pin. A quick application to do what you want would be to replace the app_on_ble_powered NULL callback with the below snippet:

enum arch_main_loop_callback_ret user_on_ble_powered(void)
{
if (ke_state_get(TASK_APP) == APP_CONNECTABLE)
GPIO_SetActive( GPIO_PORT_1, GPIO_PIN_0 );
else
GPIO_SetInactive( GPIO_PORT_1, GPIO_PIN_0 );

return GOTO_SLEEP;
}

This will work even when the device operates under sleep mode, since it will always check the state of the application and will switch on the LED. If you are under sleep mode and you switch on a pin the pin will keep its state while its under sleep but on wake up the peripheral will reinitialize to their original state from the periph_init() function so in any other implementation (like slava kindly suggests) you will have to remember the pin state and reset it to that state when waking up in the periph_init() function.

Thanks MT_dialog

jorge
Offline
Last seen:4 years 2 months ago
Joined:2016-01-25 14:20
Thanks a lot guys, sorry for

Thanks a lot guys, sorry for not answering back earlier.