Skip to content

Commit 17bc888

Browse files
authored
Adding an additional example for TTN Generic Node
Adding an additional example for TTN Generic Node to drive MLT-7525 buzzer. Example was tested on the target and works.
1 parent 8c848b9 commit 17bc888

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

examples/examples/buzzer.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Sounds a buzzer, will work only for TTN Generic node with STM32WL5x
2+
// see https://github.com/TheThingsIndustries/generic-node-se
3+
// The datasheet of the buzzer `MLT-7525` shows that the oscillation frequency is `2700Hz` so the period
4+
// is around 185us
5+
6+
#![no_std]
7+
#![no_main]
8+
9+
use defmt_rtt as _; // global logger
10+
use panic_probe as _; // panic handler
11+
12+
use stm32wlxx_hal::{
13+
self as hal,
14+
cortex_m::{self, delay::Delay},
15+
gpio::{pins, Output, PinState, PortA},
16+
pac,
17+
util::new_delay,
18+
};
19+
20+
#[hal::cortex_m_rt::entry]
21+
fn main() -> ! {
22+
let mut dp: pac::Peripherals = defmt::unwrap!(pac::Peripherals::take());
23+
let cp: pac::CorePeripherals = defmt::unwrap!(pac::CorePeripherals::take());
24+
25+
let gpioa: PortA = PortA::split(dp.GPIOA, &mut dp.RCC);
26+
let mut buzzer: Output<pins::A15> =
27+
cortex_m::interrupt::free(|cs| Output::default(gpioa.a15, cs));
28+
29+
let mut delay: Delay = new_delay(cp.SYST, &dp.RCC);
30+
31+
defmt::info!("Starting buzzer");
32+
33+
loop {
34+
for &level in &[PinState::High, PinState::Low] {
35+
buzzer.set_level(level);
36+
delay.delay_us(185);
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)