Reliably use the 4G-module

This commit is contained in:
Sofia 2026-05-15 00:06:04 +03:00
parent ec6488d373
commit a361d64c5f

View File

@ -7,6 +7,9 @@
)] )]
#![deny(clippy::large_stack_frames)] #![deny(clippy::large_stack_frames)]
use core::fmt::Write;
use alloc::str;
use esp_hal::{ use esp_hal::{
clock::CpuClock, clock::CpuClock,
delay::Delay, delay::Delay,
@ -14,6 +17,7 @@ use esp_hal::{
main, main,
spi::master::{Config, Spi}, spi::master::{Config, Spi},
time::{Duration, Instant, Rate}, time::{Duration, Instant, Rate},
uart::{self, Uart},
}; };
use esp_backtrace as _; use esp_backtrace as _;
@ -105,6 +109,61 @@ fn main() -> ! {
font_renderer.render(&mut display, "Hello World!", Position::new(70, 220)); font_renderer.render(&mut display, "Hello World!", Position::new(70, 220));
let test_delay = Delay::new();
let mut sim_rst = Output::new(peripherals.GPIO15, Level::High, OutputConfig::default());
let mut pwr_key = Output::new(peripherals.GPIO33, Level::High, OutputConfig::default());
pwr_key.set_low();
test_delay.delay_millis(1_000);
pwr_key.set_high();
test_delay.delay_millis(1_000);
sim_rst.set_low();
test_delay.delay_millis(1_000);
sim_rst.set_high();
test_delay.delay_millis(1_000);
pwr_key.set_low();
test_delay.delay_millis(1_000);
pwr_key.set_high();
test_delay.delay_millis(1_000);
log::info!("Ready!");
test_delay.delay_millis(1_000);
let mut uart = Uart::new(
peripherals.UART2,
uart::Config::default()
.with_baudrate(115200)
.with_data_bits(uart::DataBits::_8)
.with_parity(uart::Parity::None)
.with_sw_flow_ctrl(uart::SwFlowControl::Disabled),
)
.unwrap()
.with_rx(peripherals.GPIO16)
.with_tx(peripherals.GPIO17);
uart.flush().unwrap();
test_delay.delay_millis(250);
uart.write_str("ATI\r").unwrap();
uart.flush().unwrap();
test_delay.delay_millis(250);
log::info!("Wrote command");
let mut buffer = [0u8; 1024];
let length = uart.read(&mut buffer).unwrap();
log::info!("text: {:?}", str::from_utf8(&buffer[..length]));
uart.flush().unwrap();
test_delay.delay_millis(250);
uart.write_str("ATI\r").unwrap();
uart.flush().unwrap();
test_delay.delay_millis(250);
log::info!("Wrote command");
let mut buffer = [0u8; 1024];
let length = uart.read(&mut buffer).unwrap();
log::info!("text: {:?}", str::from_utf8(&buffer[..length]));
loop { loop {
let delay_start = Instant::now(); let delay_start = Instant::now();