Simvik

Trace an expansion header to the microcontroller's pins

Follow each header pin's net through resistors, a level shifter and solder bridges to the pin it ends at. A medium embedded C problem (Reading datasheets and…

medium · Reading datasheets and schematics · schematics · gpio

A customer asks which microcontroller pin each pin of the expansion header J3 reaches. Working from the Datasheet excerpt below, write const char *j3_pin(int n), which returns, for J3's pin n (1 to 10):

  • the microcontroller pin it is connected to as delivered, such as "PA5",
  • "3V3" or "GND" for a supply pin,
  • "NC" for a pin that reaches no microcontroller pin as delivered,
  • NULL for a pin number J3 does not have.

A resistor or a level-shifter channel passes the signal through; an open solder bridge does not.

Datasheet excerpt

Board schematic: J3, expansion header (2 × 5, odd pins in the top row)

J3 pinNet
1VCC_3V3
2GND
3EXP_TX
4EXP_RX
5EXP_SCK_R
6EXP_MOSI_R
7EXP_MISO
8EXP_CS
9GND
10EXP_INT

Board schematic: parts between the header and U1

U5 level shifter (A side 3.3 V, B side 5 V):
    A1 ── UART1_TX        B1 ── EXP_TX
    A2 ── UART1_RX        B2 ── EXP_RX

SPI1_SCK  ──[R21 22 Ω]── EXP_SCK_R
SPI1_MOSI ──[R22 22 Ω]── EXP_MOSI_R

SPI1_MISO ──[SB4]── EXP_MISO       SB4: solder bridge, OPEN as delivered
EXP_INT_MCU ──[SB2]── EXP_INT      SB2: solder bridge, CLOSED as delivered

Board schematic: U1 (microcontroller), pins used

PinNet
PA5SPI1_SCK
PA6SPI1_MISO
PA7SPI1_MOSI
PA9UART1_TX
PA10UART1_RX
PB6EXP_CS
PC13EXP_INT_MCU

Starter code

const char *j3_pin(int n) {
  switch (n) {
    case 1: return "3V3";
    case 2: return "GND";
    default: return NULL;
  }
}

Example tests

Supplies and chip select

for (int n = 1; n <= 2; n++) printf("J3.%d %s\n", n, j3_pin(n));
printf("J3.8 %s\n", j3_pin(8));

Expected output:

J3.1 3V3
J3.2 GND
J3.8 PB6

Learn it first

More Reading datasheets and schematics problems