Skip to content

Commit

Permalink
ongoing LoRa testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
pdgilbert committed Jul 17, 2024
1 parent 19ac501 commit 0d48b16
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 40 deletions.
9 changes: 7 additions & 2 deletions dev-testing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,13 @@ fugit = { version = "0.3.3", optional = true }
#radio-sx127x = { git = "https://github.com/rust-iot/rust-radio-sx127x", default-features = false }

# these two work together
radio = { version = "0.11.1", git = "https://github.com/rust-iot/radio-hal", rev = "7aade85b61c08161bf3422f7d148417bd38ecdc2" }
radio-sx127x = { git = "https://github.com/matheo-lucak/rust-radio-sx127x", default-features = false }
#radio = { version = "0.11.1", git = "https://github.com/rust-iot/radio-hal", rev = "7aade85b61c08161bf3422f7d148417bd38ecdc2" }
#radio-sx127x = { git = "https://github.com/matheo-lucak/rust-radio-sx127x", default-features = false }


# This radio-sx127 re-exports {Receive, Transmit} so looks after getting correct radio version.
radio-sx127x = { git = "https://github.com/pdgilbert/rust-radio-sx127x", default-features = false, branch = "ehal-1" }
#radio-sx127x = { path = "...rust-radio-sx127x", default-features = false }

# not used yet
#radio-sx1231 = { git = "https://github.com/rust-io/rust-radio-sx1231", default-features = false }
Expand Down
5 changes: 3 additions & 2 deletions examples/misc/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,10 @@ fn setup() -> (
#[cfg(feature = "stm32g4xx")]
use stm32g4xx_hal::{
gpio::{gpioa::PA8, Output, PushPull},
stm32::{Peripherals, SPI1},
pac::{Peripherals, SPI1},
prelude::*,
spi::{Pins, Spi, MODE_0},
time::{RateExtU32},
};

#[cfg(feature = "stm32g4xx")]
Expand All @@ -282,7 +283,7 @@ fn setup() -> (
gpioa.pa7.into_alternate(), // mosi on PA7
),
MODE_0,
400.khz(),
400.kHz(),
&mut rcc,
);

Expand Down
3 changes: 2 additions & 1 deletion examples/radio-sx127x/lora_spi_gps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ use cortex_m_semihosting::*;
use embedded_hal::delay::DelayNs;
use embedded_io::{Read};

use radio::Transmit;
//use radio::Transmit;
use radio_sx127x::Transmit;

use radio_sx127x::{
//Error as sx127xError, // Error name conflict with hals
Expand Down
3 changes: 2 additions & 1 deletion examples/radio-sx127x/lora_spi_receive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ use cortex_m_semihosting::*;

use embedded_hal::delay::DelayNs;

use radio::Receive;
//use radio::Receive;
use radio_sx127x::Receive;

use radio_sx127x::{
//Error as sx127xError, // Error name conflict with hals
Expand Down
81 changes: 50 additions & 31 deletions examples/radio-sx127x/lora_spi_send.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//! Transmit a simple message with LoRa using crate radio_sx127x (on SPI).
//!
//! The setup() functions make the application code common. They are in src/lora.rs.
//! The setup() functions make the application code common. They are in src/setup_all*.
//! The specific function used will depend on the HAL setting (see README.md).
//! See the section of setup() corresponding to the HAL setting for details on pin connections.
//! See the setup() corresponding to the HAL for details on pin connections.
//! The setup is using sck, miso, mosi, cs, reset and D00, D01. Not yet using D02, D03
//!
//! The same setup() function is used for examples lora_spi_send, lora_spi_receive, and
//! The same setup function is used for examples lora_spi_send, lora_spi_receive, and
//! lora_spi_gps (if the HAL setting is the same). The following is for all examples.
//!
//! See FREQUENCY in src/lora.rs to set the channel.
Expand Down Expand Up @@ -39,6 +39,10 @@
// 'CH_13_868': 866.10, 'CH_14_868': 866.40, 'CH_15_868': 866.70,
// 'CH_16_868': 867 , 'CH_17_868': 868 ,

// Errata https://semtech.my.salesforce.com/sfc/p/#E0000000JelG/a/2R000000HSPv/sqi9xX0gs6hgzl2LoPwCK0TS9GDPlMwsXmcNzJCMHjw
// Semtec stores value 0x12 at address 0x42 to indicate version V1b.
// V1a was pre-production engineering samples

#![no_std]
#![no_main]

Expand All @@ -54,7 +58,8 @@ use cortex_m_semihosting::*;

use embedded_hal::delay::DelayNs;

use radio::Transmit; // trait needs to be in scope to find methods start_transmit and check_transmit.
//use radio::Transmit; // trait needs to be in scope to find methods start_transmit and check_transmit.
use radio_sx127x::Transmit; // trait needs to be in scope to find methods start_transmit and check_transmit.

use radio_sx127x::{
//Error as sx127xError, // Error name conflict with hals
Expand All @@ -77,24 +82,38 @@ fn main() -> ! {
let (mut led, spi, spiext, delay) = setup::led_spi_spiext_delay_from_dp(dp);
led.off();

let mut lora = Sx127x::spi(spi, spiext.cs, spiext.busy, spiext.ready, spiext.reset, delay, &CONFIG_RADIO
).unwrap(); // should handle error //delay is available in lora

let lora = Sx127x::spi(spi, spiext.cs, spiext.busy, spiext.ready, spiext.reset, delay,
&CONFIG_RADIO );

let mut lora = match lora {
Ok(lr) => { hprintln!("lora setup completed.").unwrap();
lr }
Err(e) => { hprintln!("Error in lora setup. {:?}", e).unwrap();
panic!("{:?}", e) }
};

//let mut lora = lora.unwrap();

//delay is available in lora



// print out configuration (for debugging)

// let v = lora.lora_get_config();
// hprintln!("configuration {}", v).unwrap();

// hprintln!("chammel {}", lora.get_chammel()).unwrap();

//hprintln!("mode {}", lora.get_mode()).unwrap();
//hprintln!("mode {}", lora.read_register(Register::RegOpMode.addr())).unwrap();
//hprintln!("bandwidth {:?}", lora.get_signal_bandwidth()).unwrap();
//hprintln!("coding_rate {:?}", lora.get_coding_rate_4()).unwrap();
//hprintln!("spreading_factor {:?}", lora.get_spreading_factor()).unwrap();
//hprintln!("spreading_factor {:?}",
//hprintln!("invert_iq {:?}", lora.get_invert_iq()).unwrap();
//hprintln!("tx_power {:?}", lora.get_tx_power()).unwrap();
// use radio_sx127x::device::regs::Register;
//
// let v = lora.lora_get_config();
// hprintln!("configuration {}", v).unwrap();
//
// hprintln!("channel {}", lora.get_channel()).unwrap();
//
// hprintln!("mode {}", lora.get_mode()).unwrap();
// hprintln!("mode {}", lora.read_register(Register::RegOpMode.addr())).unwrap();
// hprintln!("bandwidth {:?}", lora.get_signal_bandwidth()).unwrap();
// hprintln!("coding_rate {:?}", lora.get_coding_rate_4()).unwrap();
// hprintln!("spreading_factor {:?}", lora.get_spreading_factor()).unwrap();
// hprintln!("invert_iq {:?}", lora.get_invert_iq()).unwrap();
// hprintln!("tx_power {:?}", lora.get_tx_power()).unwrap();

// transmit something

Expand All @@ -108,20 +127,20 @@ fn main() -> ! {
// }

loop {
lora.start_transmit(message).unwrap(); // should handle error
match lora.start_transmit(message) {
Ok(_b) => { hprintln!("start_transmit").unwrap() }
Err(_e) => { hprintln!("Error in lora.start_transmit()").unwrap() }
};

match lora.check_transmit() {
Ok(b) => {
if b {
hprintln!("TX complete").unwrap()
} else {
hprintln!("TX not complete").unwrap()
}
}
lora.delay_ms(1); // without some delay next returns bad. (interrupt may also be an option)

Err(_err) => {
match lora.check_transmit() {
Ok(b) => {if b {hprintln!("TX good").unwrap() }
else {hprintln!("TX bad").unwrap() }
}
Err(_e) => {
hprintln!("Error in lora.check_transmit(). Should return True or False.").unwrap()
}
}
};

lora.delay_ms(5000);
Expand Down
4 changes: 2 additions & 2 deletions src/PinMap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ PA7 mosi gpioa.pa7.into_alternate(), // mosi
), MODE_0, 400.kHz(), &mut rcc, );

PA11 CsPin Sx127x gpioa.pa11.into_push_pull_output(), //CsPin
PB4 BusyPin gpiob.pb8.into_floating_input(), //BusyPin DI00 CHANGED
PB5 ReadyPin gpiob.pb9.into_floating_input(), //ReadyPin DI01 CHANGED
PB4 BusyPin gpiob.pb4.into_floating_input(), //BusyPin DI00
PB5 ReadyPin gpiob.pb5.into_floating_input(), //ReadyPin DI01
PA0 ResetPin gpioa.pa0.into_push_pull_output(), //ResetPin
delay, &CONFIG_RADIO, ).unwrap(); // should handle error

Expand Down
3 changes: 2 additions & 1 deletion src/lora.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ use radio_sx127x::{
};

// trait needs to be in scope to find methods start_transmit and check_transmit.
pub use radio::{Receive, Transmit};
//pub use radio::{Receive, Transmit};
pub use radio_sx127x::{Receive, Transmit};

// lora and radio parameters

Expand Down

0 comments on commit 0d48b16

Please sign in to comment.