Q1:I want led on when establish a connection,and off when go to sleep,
my code as the below
void periph_init(void)
{
....
GPIO_ConfigurePin(GPIO_LED_PORT,GPIO_LED_PIN, OUTPUT, PID_GPIO, false);//P03 set to low
}
void user_before_sleep(void)
{
...
GPIO_ConfigurePin(GPIO_LED_PORT,GPIO_LED_PIN, OUTPUT, PID_GPIO, false);//set to low before sleep for Power saving
}
void user_on_connection(uint8_t connection_idx, struct gapc_connection_req_ind const *param)
{
GPIO_ConfigurePin(GPIO_LED_PORT,GPIO_LED_PIN, OUTPUT, PID_GPIO, true);//when connected set high
}
你能告诉我为什么销还是output low,I had establish connected although.
how can I change it?
Q2:
What's the meaning of this GetBits16(SYS_STAT_REG, PER_IS_DOWN ?Can I need it when device wake up??
if(GetBits16(SYS_STAT_REG, PER_IS_DOWN))
{
periph_init();
}
thank you
if modify as this below,the voltage is 0.8-0.9v
void periph_init(void)
{
....
GPIO_ConfigurePin(GPIO_LED_PORT,GPIO_LED_PIN, OUTPUT, PID_GPIO, true);//P03 set to high
}
void user_before_sleep(void)
{
...
GPIO_ConfigurePin(GPIO_LED_PORT,GPIO_LED_PIN, OUTPUT, PID_GPIO, false);//set to low before sleep for Power saving
}
void user_on_connection(uint8_t connection_idx, struct gapc_connection_req_ind const *param)
{
GPIO_ConfigurePin(GPIO_LED_PORT,GPIO_LED_PIN, OUTPUT, PID_GPIO, true);//when connected set high
}
If I close the sleep config,it's will be OK
I had spent two days to solve this strange question,please give me a help ,thank you very much.
Hi RandyYu,
As i ve mention in your previous question the peripherals are turned off when you fall to sleep but the state of the pins are retained in their previous condition. The fact that you are connected doens't mean that the device never sleeps, it means that the device wakes up in order to keep the connection alive and then sleeps in order to save power and after that it sleeps in the predefined connection interval in order to keep tha link alive. So when you set the pin high when connected the 580 will start a connection but that doesn't mean that will stay awake form that momement on, it sleep and wake up periodically therefore it will go through the user_before_sleep() and turn the output low. In order to do what you want, as i mentioned in your other post you, will have to place a variable in the handler for the connection that will remember the state of the output (the application turn the output high) and in the periph_init function check the variable if is set and Set you gpio active or inactive, and also remove the user before sleep to keep the output high while you are connected.
For example:
1) declare a variable uint8_t pin_high;
2) In the periph_init place the following code:
if(!pin_high)
GPIO_ConfigurePin(GPIO_LED_PORT, GPIO_LED_PIN, OUTPUT, PID_GPIO, false);
else
GPIO_ConfigurePin(GPIO_LED_PORT, GPIO_LED_PIN, OUTPUT, PID_GPIO, true);
3) Remove the user_before_sleep() function.
4) In the app_on_connection function:
pin_high = 1;
5) In the app_on_disconnect function:
pin_high = 0;
Thanks MT_dialog
thank you I had modified the code as you said .
need I declare the variable as this
uint8_t pin_high __attribute_((section("retention_men_area0"),zero_init));.
As you said under the connection state the slave is also can go to sleep.
So I think when wakeup from the connected state,the value of pin_high will be lost.
If I want to keep this value, it is in this way(uint8_t pin_high __attribute_((section("retention_men_area0"),zero_init));.?
thank you!
Hi RandyYu,
It depends on what kind of sleep you use, if you are in extended sleep you dont need to set the variable in the retention area, the sysram is always on so the value wont be lost in sleep mode, but if you are using deep sleep, yes you must set the variable in the retention area.
Thanks MT_dialog