Last active
March 25, 2021 10:17
-
-
Save Heusini/f609183e8393b0f3d741dc4799b90ebf 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_main] | |
#![no_std] | |
extern crate embedded_hal_spy; | |
extern crate panic_halt; | |
use at_commands::builder::CommandBuilder; | |
use core::fmt::Write; | |
use cortex_m_rt::entry; | |
use nrf52840_hal::gpio::Level; | |
use nrf52840_hal::uarte; | |
use nrf52840_hal::Delay; | |
use nrf52840_hal::Timer; | |
use particle_argon::{prelude::*, Board}; | |
#[entry] | |
fn main() -> ! { | |
let board = Board::take().unwrap(); | |
// pins for console uart | |
let pins = uarte::Pins { | |
txd: board.pins.tx.into_push_pull_output(Level::Low).degrade();, | |
rxd: board.pins.rx.into_floating_input().degrade();, | |
cts: None, | |
rts: None, | |
}; | |
let mut bootmode = board.pins.bootmode.into_push_pull_output(Level::Low); // P0.16 | |
let mut wifi_en = board.pins.wifi_en.into_open_drain_output( | |
nrf52840_hal::gpio::OpenDrainConfig::Standard0Disconnect1, | |
Level::Low, | |
); // P0.24 | |
// pins for wifi uart | |
let wifi_pins = uarte::Pins { | |
txd: board.pins.esptx.into_push_pull_output(Level::Low).degrade(), //P1.04 | |
rxd: board.pins.esprx.into_floating_input().degrade(), // P1.05 | |
// cts: None, | |
// rts: None, | |
cts: Some(board.pins.cts.into_floating_input().degrade()), //P1.07 | |
rts: Some(board.pins.rts.into_push_pull_output(Level::Low).degrade()), //P1.06 | |
}; | |
let mut t = Timer::new(board.TIMER0); | |
let mut delay = Delay::new(board.SYST); | |
let parity = uarte::Parity::EXCLUDED; | |
let baudrate = uarte::Baudrate::BAUD115200; | |
let wifi_baudrate = uarte::Baudrate::BAUD921600; | |
// uart for output to console | |
let mut uart = uarte::Uarte::new(board.UARTE0, pins, parity, baudrate); | |
// uart for wifi | |
let mut wifi_uart = uarte::Uarte::new(board.UARTE1, wifi_pins, parity, wifi_baudrate); | |
let mut read_buf = [0; 16]; | |
bootmode.set_high(); | |
delay.delay_ms(100_u32); | |
wifi_en.set_high(); | |
delay.delay_ms(100_u32); | |
loop { | |
let write_result = wifi_uart.write_str("AT\r\n"); | |
let read_result = match wifi_uart.read_timeout(&mut read_buf, &mut t, 2_000_000_u32) { | |
Ok(_) => 128, | |
Err(uarte::Error::Timeout(n)) => n, | |
Err(uarte::Error::TxBufferTooLong) => 200, | |
Err(uarte::Error::RxBufferTooLong) => 201, | |
Err(uarte::Error::BufferNotInRAM) => 202, | |
Err(uarte::Error::Transmit) => 203, | |
Err(uarte::Error::Receive) => 204, | |
}; | |
uart.write_fmt(format_args!("read result: {}\r\n", read_result)); | |
uart.write_fmt(format_args!("readbuffer: {:?}\r\n", &read_buf)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment