Last active
June 4, 2024 22:09
-
-
Save sivakov512/a65b761563e76f9b203e651aa24c0c1f to your computer and use it in GitHub Desktop.
Not working serial
This file contains hidden or 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 core::{fmt::Write as _, str::from_utf8}; | |
use embedded_hal_nb::serial::{Read, Write}; | |
use esp_backtrace as _; | |
use esp_hal::{ | |
clock::ClockControl, | |
gpio, | |
peripherals::Peripherals, | |
prelude::*, | |
uart::{self, Uart}, | |
}; | |
use esp_println::println; | |
use nb; | |
#[entry] | |
fn main() -> ! { | |
let peripherals = Peripherals::take(); | |
let system = peripherals.SYSTEM.split(); | |
let clocks = ClockControl::max(system.clock_control).freeze(); | |
let io = gpio::IO::new(peripherals.GPIO, peripherals.IO_MUX); | |
let pins = uart::TxRxPins::new_tx_rx(io.pins.gpio0, io.pins.gpio1); | |
let mut uart = Uart::new_with_config( | |
peripherals.UART0, | |
uart::config::Config { | |
baudrate: 115_200, | |
data_bits: uart::config::DataBits::DataBits8, | |
parity: uart::config::Parity::ParityNone, | |
stop_bits: uart::config::StopBits::STOP1, | |
..Default::default() | |
}, | |
Some(pins), | |
&clocks, | |
None, | |
); | |
loop { | |
// Problem is on the next line | |
while let Ok(byte) = nb::block!(uart.read()) { | |
println!("{:?}", byte); | |
writeln!(uart, "{}", from_utf8(&buf).unwrap()).unwrap(); | |
nb::block!(uart.flush()).unwrap(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment