Module gd32vf103xx_hal::serial [−][src]
Expand description
Serial Communication (USART)
This module contains the functions to utilize the USART (Universal synchronous asynchronous receiver transmitter)
Example usage:
// prelude: create handles to the peripherals and registers
let p = crate::pac::Peripherals::take().unwrap();
let mut afio = p.AFIO.constrain(&mut rcu);
let mut gpioa = p.GPIOA.split();
// USART0 on Pins A9 and A10
let pin_tx = gpioa.pa9;
let pin_rx = gpioa.pa10;
// Create an interface struct for USART0 with 9600 Baud
let serial = Serial::new(
p.USART0,
(pin_tx, pin_rx),
Config::default().baudrate(9_600.bps()),
&mut afio,
&mut rcu,
);
// separate into tx and rx channels
let (mut tx, mut rx) = serial.split();
// Write 'R' to the USART
block!(tx.write(b'R')).ok();
// Receive a byte from the USART and store it in "received"
let received = block!(rx.read()).unwrap();