-
-
Save IGBC/d23118d1a13cbfcd6efeb06721850567 to your computer and use it in GitHub Desktop.
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
#![no_std] | |
#![no_main] | |
use stm32f4xx_hal as hal; | |
use cortex_m_rt::entry; // The runtime | |
use stm32f4xx_hal::prelude::*; // STM32F1 specific functions | |
use cortex_m_semihosting::*; | |
use hal::pac; | |
use hal::gpio::GpioExt; | |
use hal::rcc::RccExt; | |
use hal::spi::Spi; | |
#[allow(unused_imports)] | |
use panic_semihosting; // When a panic occurs, dump it to openOCD | |
const FREQUENCY: i64 = 915; | |
#[entry] | |
fn main() -> ! { | |
// Get handles to the hardware objects. These functions can only be called | |
// once, so that the borrowchecker can ensure you don't reconfigure | |
// something by accident. | |
let dp = pac::Peripherals::take().unwrap(); | |
let cp = cortex_m::Peripherals::take().unwrap(); | |
let rcc = dp.RCC.constrain(); | |
let clocks = rcc.cfgr.sysclk(64.MHz()).pclk1(24.MHz()).freeze(); | |
let gpioa = dp.GPIOA.split(); | |
let gpiob = dp.GPIOB.split(); | |
let gpioc = dp.GPIOC.split(); | |
// let gpiod = dp.GPIOD.split(); | |
// let gpiof = dp.GPIOF.split(); | |
let sck = gpioa.pa5.into_alternate(); | |
let miso = gpioa.pa6.into_alternate(); | |
let mosi = gpioa.pa7.into_alternate().internal_pull_up(true); | |
let reset = gpioc.pc7.into_push_pull_output(); | |
let cs = gpiob.pb6.into_push_pull_output(); | |
let spi = Spi::new( | |
dp.SPI1, | |
(sck, miso, mosi), | |
sx127x_lora::MODE, | |
1.MHz(), | |
&clocks | |
); | |
let mut lora = match sx127x_lora::LoRa::new( | |
spi, cs, reset, FREQUENCY, | |
cp.SYST.delay(&clocks)) { | |
Ok(l) => l, | |
Err(e) => panic!("{:?}", e), | |
}; | |
hprintln!("Configuring Radio OK"); | |
loop { | |
let poll = lora.poll_irq(Some(30)); //30 Second timeout | |
match poll { | |
Ok(size) =>{ | |
hprint!("with Payload: "); | |
let buffer = lora.read_packet().unwrap(); // Received buffer. NOTE: 255 bytes are always returned | |
for i in 0..size{ | |
hprint!("{}",buffer[i] as char); | |
} | |
hprintln!(); | |
}, | |
Err(_e) => hprintln!("Timeout"), | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment