sx127x_lora
1.0.0
SEMTECH SX1276/77/78/79 기반 보드의 플랫폼 공연 드라이버. embedded-hal 특성을 구현하는 모든 장치를 지원합니다. 장치는 SPI를 통해 연결되어 있으며 재설정을 위해 추가 GPIO 핀이 필요합니다. 이 Cate는 다음을 포함하여 모든 Semtech 기반 보드와 함께 작동합니다.
라즈베리 파이를 사용하여 메시지를 보냅니다. 이 예제는 linux_embedded_hal 상자를 사용합니다.
#! [ feature ( extern_crate_item_prelude ) ]
extern crate sx127x_lora ;
extern crate linux_embedded_hal as hal ;
use hal :: spidev :: { self , SpidevOptions } ;
use hal :: { Pin , Spidev } ;
use hal :: sysfs_gpio :: Direction ;
use hal :: Delay ;
const LORA_CS_PIN : u64 = 8 ;
const LORA_RESET_PIN : u64 = 21 ;
const FREQUENCY : i64 = 915 ;
fn main ( ) {
let mut spi = Spidev :: open ( "/dev/spidev0.0" ) . unwrap ( ) ;
let options = SpidevOptions :: new ( )
. bits_per_word ( 8 )
. max_speed_hz ( 20_000 )
. mode ( spidev :: SPI_MODE_0 )
. build ( ) ;
spi . configure ( & options ) . unwrap ( ) ;
let cs = Pin :: new ( LORA_CS_PIN ) ;
cs . export ( ) . unwrap ( ) ;
cs . set_direction ( Direction :: Out ) . unwrap ( ) ;
let reset = Pin :: new ( LORA_RESET_PIN ) ;
reset . export ( ) . unwrap ( ) ;
reset . set_direction ( Direction :: Out ) . unwrap ( ) ;
let mut lora = sx127x_lora :: LoRa :: new (
spi , cs , reset , FREQUENCY , Delay )
. expect ( "Failed to communicate with radio module!" ) ;
lora . set_tx_power ( 17 , 1 ) ; //Using PA_BOOST. See your board for correct pin.
let message = "Hello, world!" ;
let mut buffer = [ 0 ; 255 ] ;
for ( i , c ) in message . chars ( ) . enumerate ( ) {
buffer [ i ] = c as u8 ;
}
let transmit = lora . transmit_payload ( buffer , message . len ( ) ) ;
match transmit {
Ok ( packet_size ) => println ! ( "Sent packet with size: {}" , packet_size ) ,
Err ( ( ) ) => println ! ( "Error" ) ,
}
} STM32F429를 사용하여 Blocking poll_irq(timeout) 기능을 사용하여 데이터를 수신합니다. 수신 된 패킷을 반 해체를 통해 인쇄합니다. 이 예제는 stm32f429_hal , cortex_m 및 panic_semihosting 상자를 사용합니다.
#! [ no_std ]
#! [ no_main ]
extern crate sx127x_lora ;
extern crate stm32f429_hal as hal ;
extern crate cortex_m ;
extern crate panic_semihosting ;
use sx127x_lora :: MODE ;
use cortex_m_semihosting :: * ;
use hal :: gpio :: GpioExt ;
use hal :: flash :: FlashExt ;
use hal :: rcc :: RccExt ;
use hal :: time :: MegaHertz ;
use hal :: spi :: Spi ;
use hal :: delay :: Delay ;
const FREQUENCY : i64 = 915 ;
# [ entry ]
fn main ( ) -> ! {
let cp = cortex_m :: Peripherals :: take ( ) . unwrap ( ) ;
let p = hal :: stm32f429 :: Peripherals :: take ( ) . unwrap ( ) ;
let mut rcc = p . RCC . constrain ( ) ;
let mut flash = p . FLASH . constrain ( ) ;
let clocks = rcc
. cfgr
. sysclk ( MegaHertz ( 64 ) )
. pclk1 ( MegaHertz ( 32 ) )
. freeze ( & mut flash . acr ) ;
let mut gpioa = p . GPIOA . split ( & mut rcc . ahb1 ) ;
let mut gpiod = p . GPIOD . split ( & mut rcc . ahb1 ) ;
let mut gpiof = p . GPIOF . split ( & mut rcc . ahb1 ) ;
let sck = gpioa . pa5 . into_af5 ( & mut gpioa . moder , & mut gpioa . afrl ) ;
let miso = gpioa . pa6 . into_af5 ( & mut gpioa . moder , & mut gpioa . afrl ) ;
let mosi = gpioa . pa7 . into_af5 ( & mut gpioa . moder , & mut gpioa . afrl ) ;
let reset = gpiof . pf13 . into_push_pull_output ( & mut gpiof . moder , & mut gpiof . otyper ) ;
let cs = gpiod . pd14 . into_push_pull_output ( & mut gpiod . moder , & mut gpiod . otyper ) ;
let spi = Spi :: spi1 (
p . SPI1 ,
( sck , miso , mosi ) ,
MODE ,
MegaHertz ( 8 ) ,
clocks ,
& mut rcc . apb2 ,
) ;
let mut lora = sx127x_lora :: LoRa :: new (
spi , cs , reset , FREQUENCY ,
Delay :: new ( cp . SYST , clocks ) ) . unwrap ( ) ;
loop {
let poll = lora . poll_irq ( Some ( 30 ) ) ; //30 Second timeout
match poll {
Ok ( size ) => {
hprint ! ( "with Payload: " ) ;
let buffer = lora . read_packet ( ) ; // Received buffer. NOTE: 255 bytes are always returned
for i in 0 ..size {
hprint ! ( "{}" , buffer [ i ] as char ) . unwrap ( ) ;
}
hprintln ! ( ) ;
} ,
Err ( ( ) ) => hprintln ! ( "Timeout" ) . unwrap ( ) ,
}
}
} 상자는 현재 라디오에서 IRQ 레지스터를 폴링하여 새로운 패킷이 도착했는지 확인합니다. 인터럽트가 모듈의 DIO_0 핀을 연결하면 대신 더 효율적입니다. 인터럽트 지원이 포함되면 embedded-hal 에서 이용할 수 있습니다. read_packet() 함수로 패킷을 검색 하여이 기능을 장치 간 기반으로 구현할 수 있습니다.
귀하가 명시 적으로 명시 적으로 명시하지 않는 한, APACHE-2.0 라이센스에 정의 된대로 귀하가 작업에 포함시키기 위해 의도적으로 제출 된 모든 기부금은 추가 이용 약관이나 조건없이 위와 같이 이중 라이센스를받습니다.