esp-hal/esp32h2-hal/examples/spi_loopback.rs
Dániel Buga 280caad378
RISC-V: Make atomic emulation opt-in (#904)
* RISC-V: Make atomic emulation opt-in

* Update embassy-executor, embassy-sync

* Don't automatically enable portable-atomic

* Update changelog

* Fix warnings
2023-11-10 11:51:47 +00:00

59 lines
1.3 KiB
Rust

//! SPI loopback test
//!
//! Folowing pins are used:
//! SCLK GPIO1
//! MISO GPIO2
//! MOSI GPIO3
//! CS GPIO11
//!
//! Depending on your target and the board you are using you have to change the
//! pins.
//!
//! This example transfers data via SPI.
//! Connect MISO and MOSI pins to see the outgoing data is read as incoming
//! data.
#![no_std]
#![no_main]
use esp32h2_hal::{
clock::ClockControl,
gpio::IO,
peripherals::Peripherals,
prelude::*,
spi::{master::Spi, SpiMode},
Delay,
};
use esp_backtrace as _;
use esp_println::println;
#[entry]
fn main() -> ! {
let peripherals = Peripherals::take();
let system = peripherals.SYSTEM.split();
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
let sclk = io.pins.gpio1;
let miso = io.pins.gpio2;
let mosi = io.pins.gpio3;
let cs = io.pins.gpio11;
let mut spi = Spi::new(peripherals.SPI2, 100u32.kHz(), SpiMode::Mode0, &clocks).with_pins(
Some(sclk),
Some(mosi),
Some(miso),
Some(cs),
);
let mut delay = Delay::new(&clocks);
loop {
let mut data = [0xde, 0xca, 0xfb, 0xad];
spi.transfer(&mut data).unwrap();
println!("{:x?}", data);
delay.delay_ms(250u32);
}
}