-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
54 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#![no_main] | ||
#![no_std] | ||
|
||
use panic_halt as _; | ||
|
||
use crate::hal::spi::{Mode, Phase, Polarity}; | ||
use crate::hal::{pac, prelude::*}; | ||
use cortex_m::asm; | ||
use cortex_m_rt::entry; | ||
use stm32f4xx_hal as hal; | ||
|
||
/// SPI mode | ||
pub const MODE: Mode = Mode { | ||
phase: Phase::CaptureOnFirstTransition, | ||
polarity: Polarity::IdleLow, | ||
}; | ||
|
||
#[entry] | ||
fn main() -> ! { | ||
let p = pac::Peripherals::take().unwrap(); | ||
|
||
let rcc = p.RCC.constrain(); | ||
let _clocks = rcc.cfgr.freeze(); | ||
|
||
let gpioa = p.GPIOA.split(); | ||
|
||
let sck = gpioa.pa5; | ||
let miso = gpioa.pa6; | ||
let mosi = gpioa.pa7; | ||
|
||
// clock speed is determined by the master | ||
let mut spi = p | ||
.SPI1 | ||
.spi_slave((sck, miso, mosi, Some(gpioa.pa4.into())), MODE); | ||
// alternativelly you could use software `chip select` | ||
// let mut spi = SpiSlave::new(p.SPI1, (sck, miso, mosi, None), MODE); | ||
// spi.set_internal_nss(false); | ||
|
||
let mut data = [0x1]; | ||
// this will block until the master starts the clock | ||
spi.transfer_in_place(&mut data).unwrap(); | ||
|
||
// when you reach this breakpoint you'll be able to inspect the variable `data` which contains the | ||
// data sent by the master | ||
asm::bkpt(); | ||
|
||
loop { | ||
continue; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters