Hi. I am adding buzzer beeping in Immediate Alert Service of ble_app_proximity example. Event thought Immediate Alert signal is sent from nRF Master Control, there is no beeping. I would like to know the reason and how to solve it.
The code is as follows: (1) In alert_signal() function:
static void alert_signal(uint8_t alert_level) {
uint32_t err_code;
switch (alert_level) {
case BLE_CHAR_ALERT_LEVEL_NO_ALERT:
err_code = bsp_indication_set(BSP_INDICATE_ALERT_OFF);
APP_ERROR_CHECK(err_code);
pwm_stop();
break;
case BLE_CHAR_ALERT_LEVEL_MILD_ALERT:
err_code = bsp_indication_set(BSP_INDICATE_ALERT_0);
APP_ERROR_CHECK(err_code);
pwm_start();
break;
case BLE_CHAR_ALERT_LEVEL_HIGH_ALERT:
err_code = bsp_indication_set(BSP_INDICATE_ALERT_3);
APP_ERROR_CHECK(err_code);
pwm_start();
break;
default:
// No implementation needed.
break;
}
}
(2) In main() function, before calling advertising_start(), the following statement is added:
init_pwm(1000L, BUZZER);
(3) The following C file is linked:
APP_PWM_INSTANCE(PWM1, 1); // Create the instance "PWM1" using TIMER1.
static volatile bool ready_flag; // A flag indicating PWM status.
void pwm_ready_callback(uint32_t pwm_id) { // PWM callback function
ready_flag = true;
}
uint32_t init_pwm(uint32_t perior, uint8_t pin) {
uint32_t err_code = 0;
nrf_gpio_pin_dir_set(pin, NRF_GPIO_PIN_DIR_OUTPUT);
nrf_gpio_pin_clear(pin);
/* 2-channel PWM, 200Hz, output on DK LED pins. */
app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_1CH(perior, pin);
pwm1_cfg.pin_polarity[0] = APP_PWM_POLARITY_ACTIVE_LOW;
/* Initialize and enable PWM. */
err_code = app_pwm_init(&PWM1, &pwm1_cfg, pwm_ready_callback);
APP_ERROR_CHECK(err_code);
/*
app_pwm_enable(&PWM1);
while (app_pwm_channel_duty_set(&PWM1, 0, 50) == NRF_ERROR_BUSY);
*/
return err_code;
}
void pwm_start(void) {
nrf_drv_gpiote_out_task_enable(BUZZER);
app_pwm_enable(&PWM1);
while (app_pwm_channel_duty_set(&PWM1, 0, 50) == NRF_ERROR_BUSY);
}
void pwm_stop(void) {
ret_code_t err_code;
app_pwm_disable(&PWM1);
nrf_drv_gpiote_out_task_disable(BUZZER);
err_code = app_pwm_uninit(&PWM1);
APP_ERROR_CHECK(err_code);
nrf_gpio_cfg_output(BUZZER);
nrf_gpio_pin_clear(BUZZER);
}
According to Immediate Alert signal, LED is indicated. So, the Immediate Alert signal is received. Also, when the last comment in int_pwm() function is uncommented, by calling init_pwm() the buzzer is beeped. But after connection is established, the beeping is stopped. This seems to indicate that some configuration is incorrect. But I am not sure what kind of setting should be modified.
I didn't modify ble_app_proximity except alert_signal() function. That is, ble_app_proximity itself works well. The program is compiled by Keil using SDK 9.0. It runs on SoftDevice S110 8.0. I tried to use SDK10.0, but the result was same.
I would appreciate having your helps and suggestion. Best regards.