Working sequencer.

This commit is contained in:
2025-08-12 20:53:24 +02:00
parent 6b15a77cb5
commit 04b6083460
2 changed files with 93 additions and 84 deletions

View File

@@ -13,8 +13,8 @@ use crate::ad5940_registers::{AFECON, AFEGENINTSTA};
use {defmt_rtt as _, panic_probe as _};
// mod ad5940;
// use ad5940::AD5940;
mod ad5940;
use ad5940::AD5940;
// mod adg2128;
// use adg2128::State;
@@ -63,27 +63,28 @@ async fn main(spawner: Spawner) {
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);
// // Set up SPI for AD5940
// let cs = Output::new(p.PC9, Level::High, Speed::Low);
// let rst = Output::new(p.PB3, Level::High, Speed::Low);
// Set up SPI for AD5940
let cs = Output::new(p.PC9, Level::High, Speed::Low);
let rst = Output::new(p.PB3, 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 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, rst);
// ad5940.reset().await.unwrap();
// Timer::after_millis(1).await;
// ad5940.system_init().await.unwrap();
let mut ad5940 = AD5940::new(spi, cs, rst);
ad5940.reset().await.unwrap();
Timer::after_millis(1).await;
ad5940.system_init().await.unwrap();
// ad5940.init_temperature().await.unwrap();
// ad5940.init_waveform().await.unwrap();
ad5940.init_waveform().await.unwrap();
ad5940.init_impedance().await.unwrap();
// // Set up I2C for ADG2128
// let i2c = i2c::I2c::new_blocking(
@@ -101,37 +102,39 @@ async fn main(spawner: Spawner) {
// electrodes.set(Electrode::E3, AD5940Pin::AIN1, State::ENABLED);
// // electrodes.set(Electrode::E12, AD5940Pin::RE0, State::ENABLED);
// Turn on the green LED
ad5940.write_reg_raw(0x0000_0004, 1 << 1).await.unwrap();
ad5940.write_reg_raw(0x0000_001C, 1 << 1).await.unwrap();
// // Sequencer test
// ad5940.sequencer_enable(true).await;
// ad5940.afecon(AFECON::WAVEGENEN, true).await;
// ad5940.wgfcw(1000).await;
// ad5940.sequencer_wait(600_000).await;
// ad5940.wgfcw(2000).await;
ad5940.sequencer_enable(true).await;
ad5940.afecon(AFECON::WAVEGENEN, true).await;
ad5940.wgfcw(1000).await;
ad5940.sequencer_wait(300_000).await;
ad5940.wgfcw(2000).await;
ad5940.sequencer_wait(160_000).await;
// ad5940.sequencer_trigger_interrupt(AFEGENINTSTA::CUSTOMINT0).await;
// ad5940.sequencer_trigger_interrupt(AFEGENINTSTA::CUSTOMINT1).await;
// ad5940.sequencer_wait(160_000).await;
// ad5940.afecon(AFECON::WAVEGENEN, false).await;
// ad5940.sequencer_enable(false).await;
ad5940.afecon(AFECON::WAVEGENEN, false).await;
ad5940.sequencer_enable(false).await;
// // Configure the sequencer cmd data sram
// ad5940.cmddatacon().await;
ad5940.cmddatacon().await;
// let start_address = 100; // 20 works
// ad5940.sequencer_cmd_write(start_address).await;
let start_address = 0;
ad5940.sequencer_cmd_write(start_address).await;
// ad5940.sequencer_info_configure(0, ad5940.seq_len, start_address).await;
// info!("{}", ad5940.seq_len);
ad5940.sequencer_info_configure(0, ad5940.seq_len, start_address).await;
// Create USB driver and start postcard-rpc server
let driver = Driver::new(p.USB, Irqs, p.PA12, p.PA11);
init_communication(driver, spawner);
// Green led task
spawner.must_spawn(green_led(led));
// spawner.must_spawn(green_led(led));
loop {
// Read chip id
// let chip_id = ad5940.get_chipid().await.unwrap();
// let chip_id = ad5940.get_chipid().await;
// info!("Chip ID: 0x{:04X}", chip_id);
// Read temperature
@@ -143,15 +146,15 @@ async fn main(spawner: Spawner) {
// info!("high");
ad5940.sequencer_trigger(0).await;
info!("Mainloop still running!");
// info!("Mainloop still running!");
Timer::after_millis(5000).await;
Timer::after_millis(250).await;
// ad5940.sequencer_trigger().await;
}
}