Serial communication

The micro:bit has a perihperal called UART, a Universal Asynchronous Receiver/Transmitter. This is a form of serial communication, data is transferred serially, i.e. one bit at a a time. It is asynchronous communication, and there is no clock signal to dictate the bitrate, intead this is agreed upon beforehand. The protocol has frames consisting of a start bit, data bits, parity bits, and stop bits. We will be using 8 bits per frame: 1 start, 6 data and 1 stop. The data rate is called the baud rate, and we will use 115200bps.


The micro:bit allows us to transmit and receive this serial communication over USB with no additional hardware.


To read and write to the serial bus from your computer, you will need to configure your tooling:


# #![allow(unused_variables)]
#fn main() {
use microbit::hal::prelude::*;
use microbit::hal::serial;
use microbit::hal::serial::BAUD115200;
// -- snip --
if let Some(p) = microbit::Peripherals::take() {
    let mut gpio = p.GPIO.split();
    // Configure RX and TX pins accordingly
    let tx = gpio.pin24.into_push_pull_output().downgrade();
    let rx = gpio.pin25.into_floating_input().downgrade();
    // Configure serial communication
    let (mut tx, _) = serial::Serial::uart0(p.UART0, tx, rx, BAUD115200).split();
    // Write string with newline and carriage return
    // This could also be a format string
    let _ = write!(tx, "serial test\n\r");

In minicom/PuTTY you should see:

serial test

This is a very simple introduction to using the UART as one way serial logging. The chapter on UART serial communication goes into much more detail.