The microbit page: Difference between revisions

From Bare Metal micro:bit
Jump to navigation Jump to search
m (Mike moved page The micro:bit page to The microbit page)
(20 intermediate revisions by the same user not shown)
Line 7: Line 7:


The {{Microbit}} is best thought of as a system with three layers:
The {{Microbit}} is best thought of as a system with three layers:
* The [[#Processor core|processor core]] is a Cortex-M0 developed by ARM.
* The [[#Processor core|processor core]] is a Cortex-M0 (or on V2, a Cortex-M4) developed by ARM.
* The [[#Microcontroller chip|microcontroller chip]], an nRF51822 developed by Nordic Semiconductor, extends the core with a collection of peripheral interfaces.
* The [[#Microcontroller chip|microcontroller chip]], an nRF51822 (or for V2, an nRF52833) developed by Nordic Semiconductor, extends the core with a collection of peripheral interfaces.
* The [[#micro:bit board|{{Microbit}} board]], developed for the BBC, adds external components like buttons, lights, and an accelerometer and magnetometer on an {{I2C}} bus.
* The [[#micro:bit board|{{Microbit}} board]], developed for the BBC, adds external components like buttons, lights, and an accelerometer and magnetometer on an {{I2C}} bus. The V2 board adds a microphone, a loudspeaker and a touch sensor.
 
This page contains exclusively documentation of the {{Microbit}} itself: for information on the tool setup for programming it, see the [[software setup]] page.
This page contains exclusively documentation of the {{Microbit}} itself: for information on the tool setup for programming it, see the appropriate [[{{Mediawiki:Mainpage}}#Appendices|appendices]] of the book.


==Processor core==
==Processor core==
The [https://developer.arm.com/products/processors/cortex-m/cortex-m0 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.
The [https://developer.arm.com/ip-products/processors/cortex-m/cortex-m0 Cortex-M0] (V1) or [https://developer.arm.com/ip-products/processors/cortex-m/cortex-m4 Cortex-M4] (V2) 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.  The V2 processor adds its own set of 32-bit Thumb2 instructions, so that programs contain a mixture of 16 and 32-bit instructions; this is different from the standard, "native" encoding used on the Raspberry Pi, where every instruction is 32 bits.
[[Image:Thumb-decode-preview.png|thumb|400px|right|Decoding chart for Thumb instructions|link={{filepath:Thumb-decode.pdf}}]]
[[Image:Thumb-decode-preview.png|thumb|400px|right|Decoding chart for Thumb instructions|link={{filepath:Thumb-decode.pdf}}]]
===Official documents===
* [[Media:ARM-ARM-V6m.pdf|ARM architecture reference manual]] for ARMv6-M, describing the Cortex-M0 instruction set ([http://infocenter.arm.com/help/topic/com.arm.doc.ddi0419d/DDI0419D_armv6m_arm.pdf source]).
* [[Media:ARM-Thumb-QRC.pdf|Quick reference card]] ([http://infocenter.arm.com/help/topic/com.arm.doc.qrc0006e/QRC0006_UAL16.pdf source]).
* [[Media:Cortex-M0-generic-ug.pdf|Generic user guide]] for Cortex-M0 ([http://infocenter.arm.com/help/topic/com.arm.doc.dui0497a/DUI0497A_cortex_m0_r0p0_generic_ug.pdf source]).
* [[Media:Cortex-M0-tech-ref.pdf|Technical reference manual]] for Cortex-M0 ([http://infocenter.arm.com/help/topic/com.arm.doc.ddi0432c/DDI0432C_cortex_m0_r0p0_trm.pdf source]).
* Some information on the strucuture of [http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dai0321a/BIHGJICF.html Cortex-M0 pipeline].


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.
===For Cortex-M0===
* [[Media:ARM-ARM-V6m.pdf|ARM architecture reference manual]] for ARMv6-M, describing the Cortex-M0 instruction set ([https://developer.arm.com/documentation/ddi0419/latest source]).
* [[Media:ARM-Thumb-QRC.pdf|Quick reference card]] ([https://developer.arm.com/documentation/qrc0006/latest source]).
* [[Media:Cortex-M0-generic-ug.pdf|Generic user guide]] for Cortex-M0 ([https://developer.arm.com/documentation/dui0497/latest source]).
* [[Media:Cortex-M0-tech-ref.pdf|Technical reference manual]] for Cortex-M0 ([https://developer.arm.com/documentation/ddi0432/latest source]).
 
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.  We follow the same restrictions with the software for V2.
 
===For Cortex-M4===
* [[Media:ARM-ARM-V7m.pdf|ARM architecture reference manual]] for ARMv7-M, describing the instruction set implemented on Cortex-M4 ([https://developer.arm.com/documentation/ddi0403/latest source]).  ''The earlier instruction set is a subset of this one, so no harm will result if you use the shorter and simpler ARMv6-M manual as a reference when programming.''
* [[Media:Cortex-M4-generic-ug.pdf|Generic user guide]] for Cortex-M4 ([https://developer.arm.com/documentation/dui0553/latest source]).
* [[Media:Cortex-M4-tech-ref.pdf|Technical reference manual]] for Cortex-M4 ([https://developer.arm.com/documentation/ddi0439/latest source]).


===See also===
===See also===
Line 30: Line 34:


==Microcontroller chip==
==Microcontroller chip==
===For Version 1===
[[Image:nRF51822.jpg|right|frame|nRF51822 chip and 16MHz crystal]]
[[Image:nRF51822.jpg|right|frame|nRF51822 chip and 16MHz crystal]]
The [https://www.nordicsemi.com/eng/Products/Bluetooth-low-energy/nRF51822 nRF51822] contains an implementation of the processor core that runs with a 16MHz clock, together with 16MB of RAM and 256MB 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.
The [https://www.nordicsemi.com/eng/Products/Bluetooth-low-energy/nRF51822 nRF51822] contains an implementation of the Cortex-M0 processor core that runs with a 16MHz clock, together with 16MB of RAM and 256MB 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.
* [[Media:NRF51822-product-spec.pdf|Product specification]] for the nRF51822, containing the mechanical and electrical parts of the datasheet ([http://infocenter.nordicsemi.com/pdf/nRF51822_PS_v3.1.pdf source]).
* [[Media:NRF51822-product-spec.pdf|Product specification]] for the nRF51822, containing the mechanical and electrical parts of the datasheet ([http://infocenter.nordicsemi.com/pdf/nRF51822_PS_v3.1.pdf source]).
* [[Media:NRF51822-ref-manual.pdf|Reference manual]] for the nRF51822, containing detailed programming information for the peripheral interfaces ([http://infocenter.nordicsemi.com/pdf/nRF51_RM_v3.0.pdf source]).
* [[Media:NRF51822-ref-manual.pdf|Reference manual]] for the nRF51822, containing detailed programming information for the peripheral interfaces ([http://infocenter.nordicsemi.com/pdf/nRF51_RM_v3.0.pdf source]).
* Product anomaly notices for the nRF51822: [[Media:NRF58122-pan-v3.2.pdf|version 3.2]], [[Media:NRF58122-pan-v2.4.pdf|version 2.4]].
* Product anomaly notices for the nRF51822: [[Media:NRF58122-pan-v3.2.pdf|version 3.2]], [[Media:NRF58122-pan-v2.4.pdf|version 2.4]].
* A sneak peek at the [[nRF51822 die shot|nRF58122 die]].
Handy Q&A from the Nordic site:
Handy Q&A from the Nordic site:
* [https://devzone.nordicsemi.com/f/nordic-q-a/3984/is-it-necessary-to-suspend-twi-for-each-byte-read Is it necessary to SUSPEND TWI for each byte read?] ([[Note about I2C implementation|Local copy]]).
* [https://devzone.nordicsemi.com/f/nordic-q-a/3984/is-it-necessary-to-suspend-twi-for-each-byte-read Is it necessary to SUSPEND TWI for each byte read?] ([[Note about I2C implementation|Local copy]]).
===For Version 2===
The [https://www.nordicsemi.com/Products/Low-power-short-range-wireless/nRF52833 nRF52833] contains an Cortex-M4 core running at 64MHz, with 128kB of RAM and 512kB of flash ROM.  It also contains a richer set of peripherals than the nRF51822, but most of the peripherals retained from the nRF51 family can be programmed identically.
* [[Media:NRF52833-product-spec.pdf|Product specification]] for the nRF52833 ([https://infocenter.nordicsemi.com/index.jsp?topic=%2Fstruct_nrf52%2Fstruct%2Fnrf52833.html source]), containing both electrical and programming information.
* [[Media:NRF52-migration.pdf|Migration guide]] for moving programs from the nRF51 family to the nRF52 ([http://infocenter.nordicsemi.com/pdf/nRF52_Series_Migration.pdf source]).


==micro:bit board==
==micro:bit board==
===Version 1===
The {{Microbit}} board adds connections and external devices to the nRF51822 chip. A [[Media:True-microbit-schematic.pdf|schematic]] is available, and also a more colourful [[Media:Microbit-schematic.pdf|schematic]] for a reference design.  There are:
The {{Microbit}} board adds connections and external devices to the nRF51822 chip. A [[Media:True-microbit-schematic.pdf|schematic]] is available, and also a more colourful [[Media:Microbit-schematic.pdf|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.<ref>The irregular pattern helps to reduce the impression of flickering when the display is multiplexed; also, row 2 consists of seven LEDs in a hexagonal pattern, and we use that pattern for the {{SSOD}}.</ref> 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.
* 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. 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.  On the V2 board, the LEDs have a more orderly logical arrangement in five rows of five.
* two tactile switches, labelled A and B.
* two tactile switches, labelled A and B.
* a UART interface, connected to a host computer via USB.
* a UART interface, connected to a host computer via USB.
Line 51: Line 61:
[[Image:Micro-bit-pinout.png|600px|thumb|none|{{Microbit}} pinout ([http://microbit.org/guide/hardware/pins source])]]
[[Image:Micro-bit-pinout.png|600px|thumb|none|{{Microbit}} pinout ([http://microbit.org/guide/hardware/pins source])]]


The following table gives the correspondence between the edge connector pads and bits in the GPIO register of the Nordic chip.  Predefined constants @PAD0@, @PAD1@, ... in the header file @hardware.h@ correspond to value 3, 2, ..., so it is rarely necessary to use these values directly in programm code.  The pin numbers on the chip are not needed unless you want to design your own circuit board.
The following table gives the correspondence between the edge connector pads and bits in the GPIO register of the Nordic chip.  Predefined constants @PAD0@, @PAD1@, ... in the header file @hardware.h@ correspond to values 3, 2, ..., so it is rarely necessary to use these values directly in programm code.  The pin numbers on the chip are not needed unless you want to design your own circuit board.  


{| class="wikitable"
{| class="wikitable"
!Pad on board!!Pin on chip!!Bit in register
!Pad on board!!Pin on chip!!Bit in register!!ADC channel!!Function
|-
|-
|PAD0||20||3
|PAD0||7||P0.03||AIN4||
|-
|-
|PAD1||19||2
|PAD1||6||P0.02||AIN3||
|-
|-
|PAD2||18||1
|PAD2||5||P0.01||AIN2||
|-
|-
|PAD3||21||4
|PAD3||8||P0.04||AIN5||Column 1
|-
|-
|PAD4||22||5
|PAD4||9||P0.05||AIN6||Column 2
|-
|-
|PAD5||37||17
|PAD5||25||P0.17|| ||Button A
|-
|-
|PAD6||30||12
|PAD6||18||P0.12|| ||Column 9
|-
|-
|PAD7||29||11
|PAD7||17||P0.11|| ||Column 8
|-
|-
|PAD8||38||18
|PAD8||26||P0.18|| ||
|-
|-
|PAD9||28||10
|PAD9||16||P0.10|| ||Column 7
|-
|-
|PAD10||23||6
|PAD10||10||P0.06||AIN7||Column 3
|-
|-
|PAD11||9||26
|PAD11||45||P0.26|| ||Button B
|-
|-
|PAD12||40||20
|PAD12||28||P0.20|| ||Accessibility
|-
|-
|PAD13||6||23
|PAD13||42||P0.23|| ||SPI.SCLK
|-
|-
|PAD14||5||22
|PAD14||41||P0.22|| ||SPI.MISO
|-
|-
|PAD15||4||21
|PAD15||40||P0.21|| ||SPI.MOSI
|-
|-
|PAD16||34||16
|PAD16||22||P0.16|| ||
|-
|-
|PAD19||17||0
|PAD19||4||P0.00|| ||I2C.SCL
|-
|-
|PAD20||16||30
|PAD20||3||P0.30|| ||I2C.SDA
|}
|}


In addition, there are a number of [[Micro:bit test points|test points]] on the board that give access to interesting signals, including the TX and RX lines of the UART.
In addition, there are a number of [[Micro:bit test points|test points]] on the V1 board that give access to interesting signals, including the TX and RX lines of the UART.
 
In fact, the {{Microbit}} 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.  Don't try it!)
 
===Version 2===
The V2 board has the same hardware elements as the V1 board, but adds a microphone, a loudspeaker and a touch sensor: driving these is left as a challenge in this book.  A [[Media:Microbit-v2-schematic.pdf|schematic]] for the V2 board is available.
 
* The KL26Z on the V1 board is replaced by a more powerful KL27Z on the V2 board, but as before we will become involved with it.  The 3.3V supply on the V2 board is provided by a separate LDO voltage regulator.


In fact, the {{Microbit}} 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 boardIt 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 display on the V2 board is wired more logically as a 5 &times; 5 array, with the controlling pins spread across both GPIO device registersAppropriate changes to the driving software are explained in each experiment.


The pins of the V2 board (or, properly speaking, the solder balls on its BGA package) are wired to pads on the board differently from the V1.  The differences are reflected in different definitions in the file @hardware.h@, so that few changes to actual programs are needed.  In the table, the notation <code>''a''.''b''</code> denotes bit <code>''b''</code> in port <code>GPIO''a''</code>.
{| class="wikitable"
!Pad on board!!Pin on chip!!Bit in register!!ADC channel!!Function
|-
|PAD0||A12||P0.02||AIN0||
|-
|PAD1||B13||P0.03||AIN1||
|-
|PAD2||J1||P0.04||AIN2||
|-
|PAD3||A8||P0.31||AIN7||Column 3
|-
|PAD4||B11||P0.28||AIN4||Column 1
|-
|PAD5||AC9||P0.14|| ||Button A
|-
|PAD6||A16||P1.05|| ||Column 4
|-
|PAD7||T2||P0.11|| ||Column 2
|-
|PAD8||J24||P0.10|| ||
|-
|PAD9||L24||P0.09|| ||
|-
|PAD10||B9||P0.30||AIN6||Column 5
|-
|PAD11||B17||P0.23|| ||Button B
|-
|PAD12||U1||P0.12|| ||Accessibility
|-
|PAD13||AD12||P0.17|| ||SPI.SCLK
|-
|PAD14||F2||P0.01|| ||SPI.MISO
|-
|PAD15||AD8||P0.13|| ||SPI.MOSI
|-
|PAD16||W24||P1.02|| ||
|-
|PAD19||G1||P0.26|| ||I2C.SCL
|-
|PAD20||AD22||P1.00|| ||I2C.SDA
|}
The V2 board has test points like the V1 board, but many of these are covered in black solder mask for safety, so it is harder to solder to them.
==Factory software==
The supplied software for the {{Microbit}} itself has three layers.
The supplied software for the {{Microbit}} itself has three layers.
* An instance of the MBED library.
* An instance of the MBED library.
Line 108: Line 170:
* [[Media:IS31FL3731.pdf|Datasheet]] for the IS31FL3731 I2C LED driver chip used on the scroll:bit add-on board.
* [[Media:IS31FL3731.pdf|Datasheet]] for the IS31FL3731 I2C LED driver chip used on the scroll:bit add-on board.
* [[Media:WS1282B.pdf|Datasheet]] for WS1282B "neopixels".
* [[Media:WS1282B.pdf|Datasheet]] for WS1282B "neopixels".
 
* [[Media:MCP7940N-datasheet.pdf|Datasheet]] for the MCP7940N {{I2C}} real time clock, used in Kitronik products ([https://ww1.microchip.com/downloads/en/DeviceDoc/20005010F.pdf source]).
 
----
<references/>

Revision as of 16:29, 30 September 2021

Copyright © 2019–21 J. M. Spivey. All rights reserved.

This page is Grand Central Station for micro:bit hardware documentation. I have tried to include a copy of every document I used in writing the book, 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 (or on V2, a Cortex-M4) developed by ARM.
  • The microcontroller chip, an nRF51822 (or for V2, an nRF52833) 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. The V2 board adds a microphone, a loudspeaker and a touch sensor.

This page contains exclusively documentation of the micro:bit itself: for information on the tool setup for programming it, see the software setup page.

Processor core

The Cortex-M0 (V1) or Cortex-M4 (V2) 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. The V2 processor adds its own set of 32-bit Thumb2 instructions, so that programs contain a mixture of 16 and 32-bit instructions; this is different from the standard, "native" encoding used on the Raspberry Pi, where every instruction is 32 bits.

Decoding chart for Thumb instructions

For Cortex-M0

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. We follow the same restrictions with the software for V2.

For Cortex-M4

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 home-made list of common Thumb instructions.

Microcontroller chip

For Version 1

nRF51822 chip and 16MHz crystal

The nRF51822 contains an implementation of the Cortex-M0 processor core that runs with a 16MHz clock, together with 16MB of RAM and 256MB 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.

Handy Q&A from the Nordic site:

For Version 2

The nRF52833 contains an Cortex-M4 core running at 64MHz, with 128kB of RAM and 512kB of flash ROM. It also contains a richer set of peripherals than the nRF51822, but most of the peripherals retained from the nRF51 family can be programmed identically.

micro:bit board

Version 1

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. 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. On the V2 board, the LEDs have a more orderly logical arrangement in five rows of five.
  • 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. Product page, datasheet (source).
  • a 3-axis magnetometer chip MAG3110, connected to the same I2C bus. Product page, datasheet (source)
  • Alternatively (on more recent boards), a single chip LSM303AGR with a different I2C address 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)

The following table gives the correspondence between the edge connector pads and bits in the GPIO register of the Nordic chip. Predefined constants PAD0, PAD1, ... in the header file hardware.h correspond to values 3, 2, ..., so it is rarely necessary to use these values directly in programm code. The pin numbers on the chip are not needed unless you want to design your own circuit board.

Pad on board Pin on chip Bit in register ADC channel Function
PAD0 7 P0.03 AIN4
PAD1 6 P0.02 AIN3
PAD2 5 P0.01 AIN2
PAD3 8 P0.04 AIN5 Column 1
PAD4 9 P0.05 AIN6 Column 2
PAD5 25 P0.17 Button A
PAD6 18 P0.12 Column 9
PAD7 17 P0.11 Column 8
PAD8 26 P0.18
PAD9 16 P0.10 Column 7
PAD10 10 P0.06 AIN7 Column 3
PAD11 45 P0.26 Button B
PAD12 28 P0.20 Accessibility
PAD13 42 P0.23 SPI.SCLK
PAD14 41 P0.22 SPI.MISO
PAD15 40 P0.21 SPI.MOSI
PAD16 22 P0.16
PAD19 4 P0.00 I2C.SCL
PAD20 3 P0.30 I2C.SDA

In addition, there are a number of test points on the V1 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. Don't try it!)

Version 2

The V2 board has the same hardware elements as the V1 board, but adds a microphone, a loudspeaker and a touch sensor: driving these is left as a challenge in this book. A schematic for the V2 board is available.

  • The KL26Z on the V1 board is replaced by a more powerful KL27Z on the V2 board, but as before we will become involved with it. The 3.3V supply on the V2 board is provided by a separate LDO voltage regulator.
  • The display on the V2 board is wired more logically as a 5 × 5 array, with the controlling pins spread across both GPIO device registers. Appropriate changes to the driving software are explained in each experiment.

The pins of the V2 board (or, properly speaking, the solder balls on its BGA package) are wired to pads on the board differently from the V1. The differences are reflected in different definitions in the file hardware.h, so that few changes to actual programs are needed. In the table, the notation a.b denotes bit b in port GPIOa.

Pad on board Pin on chip Bit in register ADC channel Function
PAD0 A12 P0.02 AIN0
PAD1 B13 P0.03 AIN1
PAD2 J1 P0.04 AIN2
PAD3 A8 P0.31 AIN7 Column 3
PAD4 B11 P0.28 AIN4 Column 1
PAD5 AC9 P0.14 Button A
PAD6 A16 P1.05 Column 4
PAD7 T2 P0.11 Column 2
PAD8 J24 P0.10
PAD9 L24 P0.09
PAD10 B9 P0.30 AIN6 Column 5
PAD11 B17 P0.23 Button B
PAD12 U1 P0.12 Accessibility
PAD13 AD12 P0.17 SPI.SCLK
PAD14 F2 P0.01 SPI.MISO
PAD15 AD8 P0.13 SPI.MOSI
PAD16 W24 P1.02
PAD19 G1 P0.26 I2C.SCL
PAD20 AD22 P1.00 I2C.SDA

The V2 board has test points like the V1 board, but many of these are covered in black solder mask for safety, so it is harder to solder to them.

Factory software

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".
  • Datasheet for the MCP7940N I2C real time clock, used in Kitronik products (source).