This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Buzzer beep in Immediate Alert Service

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.

Parents
  • Hi shin

    Try the following code where I have combined PWM with ble_app_proximity example. It is for nRF51 SDK 10.0.0 and PCA10028

    ble_app_proximity_with_pwm.zip

    Connect to the device and write 0x00, 0x01 or 0x02 to the Immediate Alert Service in order to change the alert level and to change PWM duty cycle on LED_4

    Update 10.2.2016 Below is a similar example, but with 4x PWM channels connected to 4 LEDs on the nRF51-DK board. All PWMs are generated with the app_pwm library which uses TIMER+PPI+GPIOTE peripherals. Use the same procedure as before to change the duty cycle of the PWMs.

    ble_app_proximity_with_4xPWMs.zip

  • @hark. Verified that the ble_app_proximity_with_pwm.zip that I attached before works on my iphone, both with lightblue and with nRFToolbox proximity app. However, it was necessary to go to bluetooth settings and select the "i" for the device and then select "forget device". Then turn of Bluetooth and turn it on again. This procedure erases the bonding information on the iphone and will make the iphone create new gatt table for the proximity app. Otherwise, an old gatt table could be present on your iphone from another application that you connected with previously.

    On lightblue, just send 0x01 or 0x02 to the immediate alert service. On nRFToolbox proximity app, connect and then press the "Find Me" button

Reply
  • @hark. Verified that the ble_app_proximity_with_pwm.zip that I attached before works on my iphone, both with lightblue and with nRFToolbox proximity app. However, it was necessary to go to bluetooth settings and select the "i" for the device and then select "forget device". Then turn of Bluetooth and turn it on again. This procedure erases the bonding information on the iphone and will make the iphone create new gatt table for the proximity app. Otherwise, an old gatt table could be present on your iphone from another application that you connected with previously.

    On lightblue, just send 0x01 or 0x02 to the immediate alert service. On nRFToolbox proximity app, connect and then press the "Find Me" button

Children
No Data
Related