Created basic lib for AD5940.

This commit is contained in:
2025-07-16 09:55:10 +02:00
parent 73b96c2756
commit c6b250a4a8
2 changed files with 91 additions and 6 deletions

View File

@@ -4,23 +4,57 @@
use defmt::*;
use embassy_executor::Spawner;
use embassy_stm32::gpio::{Level, Output, Speed};
use embassy_stm32::{spi, Config};
use embassy_time::Timer;
use {defmt_rtt as _, panic_probe as _};
mod ad5940;
use ad5940::AD5940;
#[embassy_executor::main]
async fn main(_spawner: Spawner) {
let p = embassy_stm32::init(Default::default());
let mut config = Config::default();
{
use embassy_stm32::rcc::*;
config.rcc.pll1 = Some(Pll {
source: PllSource::HSI,
prediv: PllPreDiv::DIV4,
mul: PllMul::MUL8,
divp: Some(PllDiv::DIV2),
divq: Some(PllDiv::DIV2),
divr: Some(PllDiv::DIV2),
})
}
let p = embassy_stm32::init(config);
info!("Hello World!");
let mut led = Output::new(p.PA5, Level::High, Speed::Low);
// let mut led = Output::new(p.PA5, Level::High, Speed::Low);
let cs = Output::new(p.PC9, Level::High, Speed::Low);
let spi = spi::Spi::new_blocking(
p.SPI1,
p.PA5, // SCK
p.PA7, // MOSI
p.PA6, // MISO
spi::Config::default()
);
let mut ad5940 = AD5940::new(spi, cs);
loop {
info!("high");
led.set_high();
// Read chip id
let chip_id = ad5940.get_chipid().unwrap();
info!("Chip ID: 0x{:04X}", chip_id);
// info!("high");
// led.set_high();
Timer::after_millis(500).await;
info!("low");
led.set_low();
// info!("low");
// led.set_low();
Timer::after_millis(500).await;
}
}