I want to use a buzzer on my board.
The environment in use is below.
· SDK15
· Nrf 52
· Nrf 52832_xxaa
· S132_nrf52_6.0.0_softdevice.hex
My start is "nRF5_SDK_15.0.0_a53641a \ examples \ ble_peripheral \ ble_app_uart".
I added the PWM function by referring to the following.
"nRF5_SDK_15.0.0_a53641a\examples\peripheral\pwm_driver"
The following was added.
--------------------------------------------------------------------------------
nrf_pwm_sequence_t seq_bz =
{
.values.p_common = 0,
.length = 0,
.repeats = 0,
.end_delay = 0
};
static nrf_drv_pwm_t m_pwm_bz = NRF_DRV_PWM_INSTANCE(0);
#define USED_PWM(idx) (1UL << idx)
static uint8_t m_used = 0;
void pwm_init(void)
{
//**4kHz 50%
nrf_drv_pwm_config_t const pwm_config_bz =
{
.output_pins =
{
BUZZER_PIN_NUMBER, // channel 0
NRF_DRV_PWM_PIN_NOT_USED, // channel 1
NRF_DRV_PWM_PIN_NOT_USED, // channel 2
NRF_DRV_PWM_PIN_NOT_USED // channel 3
},
.irq_priority = APP_IRQ_PRIORITY_LOWEST,
.base_clock = NRF_PWM_CLK_4MHz,
.count_mode = NRF_PWM_MODE_UP,
.top_value = 1000,
.load_mode = NRF_PWM_LOAD_INDIVIDUAL,
.step_mode = NRF_PWM_STEP_AUTO
};
APP_ERROR_CHECK(nrf_drv_pwm_init(&m_pwm_bz, &pwm_config_bz, NULL));
m_used |= USED_PWM(0);
static nrf_pwm_values_individual_t const seq_values_bz[] =
{
500
};
seq_bz.values.p_individual = seq_values_bz;
seq_bz.length = NRF_PWM_VALUES_LENGTH(seq_values_bz);
}
void pwm_call(void)
{
NRF_LOG_INFO("pwm_call.");
nrf_drv_pwm_simple_playback(&m_pwm_bz, &seq_bz, 500, NRF_DRV_PWM_FLAG_STOP);
}
--------------------------------------------------------------------------------
I made a comment for the following as a precaution.
--------------------------------------------------------------------------------
bool erase_bonds;
buttons_leds_init(&erase_bonds);
--------------------------------------------------------------------------------
We have defined the following settings.
--------------------------------------------------------------------------------
#define NRFX_PWM_ENABLED 1
#define PWM_ENABLED 1
#define PWM0_ENABLED 1
#define PWM1_ENABLED 1
#define PWM2_ENABLED 1
#define APP_PWM_ENABLED 1
--------------------------------------------------------------------------------
Call pwm_init() with main().
The buzzer sounds by calling the function below.
--------------------------------------------------------------------------------
void pwm_call(void)
--------------------------------------------------------------------------------
But the buzzer does not sound.
I tried it against the LED just in case.
But the LED does not shine.
I looked over a bit here.
Do you need something to coexist PWM and software devices?
Please give me advice.