* make pins optional for Spi::new (master, full-duplex mode)
* add additional method to setup spi pins (master, full-duplex mode)
* add additional method to setup spi pins (master, half-duplex mode)
* remove generic type parameters for Spi::new
* update documentation
* make `with_pins` could be chained
* update CHANGELOG.md
* update CHANGELOG.md
* make the return value of a method like `with_{*}` owned
* fix (maybe?) all broken examples caused by the change (esp32-hal)
* fix (maybe?) all broken examples caused by the change (esp32c2-hal)
* fix (maybe?) all broken examples caused by the change (esp32c3-hal)
* fix (maybe?) all broken examples caused by the change (esp32c6-hal)
* fix (maybe?) all broken examples caused by the change (esp32h2-hal)
* fix (maybe?) all broken examples caused by the change (esp32s2-hal)
* fix (maybe?) all broken examples caused by the change (esp32s3-hal)
* rerun 'cargo fmt' for esp-hal-common
* rerun 'cargo fmt' for the rest of examples
62 lines
1.4 KiB
Rust
62 lines
1.4 KiB
Rust
//! SPI loopback test
|
|
//!
|
|
//! Folowing pins are used:
|
|
//! SCLK GPIO12
|
|
//! MISO GPIO11
|
|
//! MOSI GPIO13
|
|
//! CS GPIO10
|
|
//!
|
|
//! 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 esp32s3_hal::{
|
|
clock::ClockControl,
|
|
gpio::IO,
|
|
peripherals::Peripherals,
|
|
prelude::*,
|
|
spi::{
|
|
master::{prelude::*, 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.gpio12;
|
|
let miso = io.pins.gpio11;
|
|
let mosi = io.pins.gpio13;
|
|
let cs = io.pins.gpio10;
|
|
|
|
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);
|
|
}
|
|
}
|