Note: I've just migrated to a different physical server to run Spivey's Corner,
with a new architecture, a new operating system, a new version of PHP, and an updated version of MediaWiki.
Please let me know if anything needs adjustment! – Mike

The BBC micro:bit (Digital Systems)

Copyright © 2024 J. M. Spivey
Jump to navigation Jump to search

This page is Grand Central for micro:bit hardware documentation. I have tried to include a copy of every document I used in developing the course, or at least a link to it. Where a local copy exists, a link to it is shown in the text below, and the source link is added at the end of the sentence. I have included copies and links in good faith, but copyright holders are welcome to email me and ask for material to be removed.

The micro:bit is best thought of as a system with three layers:

  • The processor core is a Cortex-M0 developed by ARM.
  • The microcontroller chip, an nRF51822 developed by Nordic Semiconductor, extends the core with a collection of peripheral interfaces.
  • The micro:bit board, developed for the BBC, adds external components like buttons, lights, and an accelerometer and magnetometer on an I2C bus.

This page contains exclusively documentation of the micro:bit itself: for information on the tool setup for programming it, see the labs page and other pages linked to it.

Processor core

The Cortex-M0 core is an ARM processor, with sixteen 32-bit registers and a RISC-style instruction set. Like other microcontroller-oriented versions of the ARM, it omits the standard 32-bit encoding of the instruction set, and executes only programs written in the more compact 16-bit Thumb encoding.

Decoding chart for Thumb instructions

Note that the nRF51822 does not have a SysTick timer (you have to use one of the other timers instead), and does not have a Vector Table Offset Register (VTOR) for the interrupt controller, so that the vector table is always located in Flash at address 0.

See also ...

  • A chart showing Thumb instruction encodings. To use this chart, begin with table [A] in the top left, and find the entry identified by the first hexadecimal digit of the instruction at the left, and the second digit at the top. This will either identify a specific instruction, with assembly language syntax given at the right of the table, or give you a reference to one of the other tables [B] to [E]. In each table, the first hex digits of the instruction are shown to the left to the table, and sometimes a further digit at the top. The notation r1 or r2 denotes a low register, one of r0 to r7, while r/h1 denotes any register, including r8 to r12, sp, lr, pc. The notation #4*imm8 denotes an 8-bit immediate field whose (unsigned) value is multiplied by 4 – so it can express the values 0, 4, 8, ..., 1020. All immediate fields are unsigned, and all branch displacements are signed.
  • A list of common instructions that will be provided as part of the exam paper.
  • Geoffrey Brown's notes for a course similar to this one at Indiana University (source).
  • The Definitive Guide to the ARM Cortex-M0, by Joseph Yiu (Newnes Elsevier, 2011). ISBN: 978-0-12-385477-3. (LMGTFY)

Microcontroller chip

nRF51822 chip and 16MHz crystal

The nRF51822 contains an implementation of the processor core that runs with a 16MHz clock, together with 16kB of RAM and 256kB of read-only flash memory. It also contains several peripheral interfaces, including a UART, bus interfaces for I2C and SPI, a hardware random number generator, and a 2.4GHz radio interface. The processor has the single-cycle multiplier option.

micro:bit board

The micro:bit board adds connections and external devices to the nRF51822 chip. A schematic is available, and also a more colourful schematic for a reference design. There are:

  • 25 LEDs, arranged in a 5x5 matrix. Electrically, the 25 LEDs are wired as a matrix with three rows and up to nine LEDs in each row, in a seemingly irregular pattern.[1] Only one row can be used at a time, so displaying an arbitrary image requires patterns in the three rows to be illuminated in rapid succession, under processor control.
  • two tactile switches, labelled A and B.
  • a UART interface, connected to a host computer via USB.
  • a 3-axis accelerometer chip MMA8653FC, connected to the nRF51822 via an I2C bus (address 0x1d). Product page, datasheet (source).
  • a 3-axis magnetometer chip MAG3110, connected to the same I2C bus (address 0x0e). Product page, datasheet (source)
  • Alternatively (on more recent boards), a single chip LSM303AGR with a different I2C addresses (accelerometer 0x19, magnetometer 0x1e) that combines an accelerometer and a magnetometer. Product page, datasheet.

There is also an edge connector that exposes some of the nRF51822 pins, including the I2C bus and an SPI bus, for connection of external components.

micro:bit pinout (source)

In addition, there are a number of test points on the board that give access to interesting signals, including the TX and RX lines of the UART.

In fact, the micro:bit board contains a second ARM microcontroller chip, an NXP (was Freescale (was Motorola)) KL26Z – more powerful than the nRF51822 – that provides the USB interface, as well as a voltage regulator for the 3.3V supply used by the rest of the board. It does its job invisibly, and we will not need to pay any attention to it. (But if you should short the 3.3V and ground terminals of the board, this is the chip that will get hot.)

The supplied software for the micro:bit itself has three layers.

  • An instance of the MBED library.
  • An additional layer of device drivers written by programmers at the University of Lancaster, including a process scheduler.
  • Several language implementations – MicroPython, Javascript and a version of Scratch – that run partly or wholly on the board, all running on top of the Lancaster library.

We shall use none of this software, but it is useful to plunder the source code (especially the Lancaster library) for concrete examples of device programming. The MBED library and the Lancaster library use C++ to provide wrappers for lower-level features, following the pattern of initialising the hardware by declaring an instance of the driver class. We avoid this, and instead prefer to work with the underlying code, which is in each case written in pure C.

Accessories

  • Datasheet for the IS31FL3731 I2C LED driver chip used on the scroll:bit add-on board.
  • Datasheet for WS1282B "neopixels".



  1. Perhaps the irregular pattern helps to reduce the impression of flickering when the display is multiplexed; or perhaps (according to Jonny Austin) the hexagonal pattern of seven LEDs in row 2 can be used as photodiodes for a light sensor; in any event, we use that pattern for the Seven Stars of Death.