Simvik

An open-drain interrupt line, from the sensor's pin description

The datasheet says INT is open-drain and active low. Configure the pin so it reads correctly, and report when the sensor asserts it. An easy embedded C…

easy · Reading datasheets and schematics · datasheets · driver · gpio

A motion sensor signals events on its INT pin, wired to PC5. Working from the Datasheet excerpt below, write:

  • int_pin_init(), which configures PC5 so that it reads the INT line correctly. Change no other pin.
  • int_pending(), which returns 1 while the sensor has an event pending and 0 otherwise.

Read the pin type and the schematic note carefully: they decide both functions.

Datasheet excerpt

Pin description (sensor datasheet)

PinNameTypeDescription
7INTOpen-drain outputInterrupt, active low. Pulled to GND while an event is pending; released (high impedance) otherwise. Requires an external pull-up resistor (10 kΩ recommended) to VDDIO.
8VDDIOSupplyI/O supply, 1.8 V to 3.6 V

Board schematic, note 4

Sensor INT is connected to PC5. R14 (pull-up on INT) is not fitted: use the microcontroller's internal pull-up (about 40 kΩ).

GPIO registers (reference manual)

OffsetRegisterPin y occupiesValues
0x00MODERbits 2y+1:2y00 input, 01 output, 10 alternate function, 11 analog
0x0CPUPDRbits 2y+1:2y00 none, 01 pull-up, 10 pull-down
0x10IDRbit ythe level on the pin (read-only)

Starter code

void int_pin_init(void) {
  GPIOC->MODER &= ~(3u << 10);   // PC5 input
}

int int_pending(void) {
  return (GPIOC->IDR >> 5) & 1;
}

Example tests

Idle, then an event, then cleared

int_pin_init();
printf("%d", int_pending());
sensor_int(1);
printf(" %d", int_pending());
sensor_int(0);
printf(" %d\n", int_pending());

Expected output:

0 1 0

Learn it first

More Reading datasheets and schematics problems