2023-07-13 11:16:11 +02:00
|
|
|
//! This example shows how to use SPI (Serial Peripheral Interface) in the RP2040 chip.
|
|
|
|
//! No specific hardware is specified in this example. If you connect pin 11 and 12 you should get the same data back.
|
|
|
|
|
2022-08-30 00:30:47 +02:00
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
|
|
|
#![feature(type_alias_impl_trait)]
|
|
|
|
|
|
|
|
use defmt::*;
|
|
|
|
use embassy_executor::Spawner;
|
2022-08-31 22:28:47 +02:00
|
|
|
use embassy_rp::spi::{Config, Spi};
|
2023-10-15 01:57:25 +02:00
|
|
|
use embassy_time::Timer;
|
2022-08-30 00:30:47 +02:00
|
|
|
use {defmt_rtt as _, panic_probe as _};
|
|
|
|
|
|
|
|
#[embassy_executor::main]
|
|
|
|
async fn main(_spawner: Spawner) {
|
|
|
|
let p = embassy_rp::init(Default::default());
|
|
|
|
info!("Hello World!");
|
|
|
|
|
|
|
|
let miso = p.PIN_12;
|
|
|
|
let mosi = p.PIN_11;
|
|
|
|
let clk = p.PIN_10;
|
|
|
|
|
2022-08-31 22:28:47 +02:00
|
|
|
let mut spi = Spi::new(p.SPI1, clk, mosi, miso, p.DMA_CH0, p.DMA_CH1, Config::default());
|
2022-08-30 00:30:47 +02:00
|
|
|
|
|
|
|
loop {
|
|
|
|
let tx_buf = [1_u8, 2, 3, 4, 5, 6];
|
|
|
|
let mut rx_buf = [0_u8; 6];
|
|
|
|
spi.transfer(&mut rx_buf, &tx_buf).await.unwrap();
|
|
|
|
info!("{:?}", rx_buf);
|
2023-10-15 01:57:25 +02:00
|
|
|
Timer::after_secs(1).await;
|
2022-08-30 00:30:47 +02:00
|
|
|
}
|
|
|
|
}
|