The GPIO module provides every day input and outputs. You'll get logic GPIO pins that can act as outputs or inputs. With pullups or pulldowns. When inputs, you can also create pin-change interrupts that are routed the the IRQ pin.

On SAMD09-based boards the GPIO is 3V only. On ATtiny-based boards, the GPIO logic is whatever the power pin is, 3V or 5V.

The module base register address for the GPIO module is 0x01

 Function Registers

Register
Address

Function
Name

Register
Size

Notes

0x02

DIRSET

32 bits

Write Only

0x03

DIRCLR

32 bits

Write Only

0x04

GPIO

32 bits

Read/Write

0x05

SET

32 bits

Write Only

0x06

CLR

32 bits

Write Only

0x07

TOGGLE

32 bits

Write Only

0x08

INTENSET

32 bits

Write Only

0x09

INTENCLR

32 bits

Write Only

0x0A

INTFLAG

32 bits

Read Only

0x0B

PULLENSET

32 bits

Write Only

0x0C

PULLENCLR

32 bits

Write Only

Writes of GPIO function registers should contain 4 data bytes (32 bits) following the initial register data bytes. Each bit in these registers represents a GPIO pin on PORTA of the seesaw device.

If the corresponding pin does not exist on the SeeSaw device, then reading or writing the bit has no effect.

We decided to go with this method to make GPIO toggling fast (rather than having one i2c transaction per individual pin control) but the host processor will need to do a little work to keep the pins identified.

GPIO register setup on SAMD09:

Bit 31

Bit 30

Bit 29

Bit 28

Bit 27

.  .  .

Bit 4

Bit 3

Bit 2

Bit 1

Bit 0

PA31

PA30

PA29

PA28

PA27

.  .  .

PA04

PA03

PA02

PA01

PA00

GPIO register setup on ATTiny8x7:

(this is the same as the megaTinyCore pin mapping)

  • Bit 0: PA4
  • Bit 1: PA5
  • Bit 2: PA6
  • Bit 3: PA7
  • Bit 4: PB7
  • Bit 5: PB6
  • Bit 6: PB5
  • Bit 7: PB4
  • Bit 8: PB3
  • Bit 9: PB2
  • Bit 10: PB1
  • Bit 11: PB0
  • Bit 12: PC0
  • Bit 13: PC1
  • Bit 14: PC2
  • Bit 15: PC3
  • Bit 16: PC4
  • Bit 17: PC5
  • Bit 18: PA1
  • Bit 19: PA2
  • Bit 20: PA3

DIRSET (0x02, 32 bits, Write Only)

Writing a 1 to any bit in this register sets the direction of the corresponding pin to OUTPUT.

Writing zeros to this register has no effect.

DIRCLR (0x03, 32 bits, Write Only)

Writing a 1 to any bit in this register sets the direction of the corresponding pin to INPUT.

Writing zeros to this register has no effect.

GPIO (0x04, 32 bits, Read/Write)

When this register is written, all bits that are set to 0 will have their corresponding pins set LOW.

All bits that are set to 1 will have their corresponding pins set HIGH.

Reading this register reads all pins on of the seesaw device. On the Attiny series please wait at least 250uS between command write and data read to allow the data to be read and formatted for retrieval. Reading this register will also reset the IRQ pin if it was configured.

SET (0x05, 32 bits, Write Only)

Writing a 1 to any bit in this register writes the corresponding pin HIGH.

Writing zeros to this register has no effect.

CLR (0x06, 32 bits, Write Only)

Writing a 1 to any bit in this register writes the corresponding pin LOW.

Writing zeros to this register has no effect.

TOGGLE (0x07, 32 bits, Write Only)

Writing a 1 to any bit in this register toggles the corresponding pin.

Writing zeros to this register has no effect.

INTENSET (0x08, 32 bits, Write Only)

Writing a 1 to any bit in this register enables the interrupt on the corresponding pin. When the value on this pin changes, the corresponding bit will be set in the INTFLAG register.

Writing zeros to this register has no effect.

INTENCLR (0x09, 32 bits, Write Only)

Writing a 1 to any bit in this register disables the interrupt on the corresponding pin.

Writing zeros to this register has no effect.

INTFLAG (0x0A, 32 bits, Read Only)

This register hold the status of all GPIO interrupts. When an interrupt fires, the corresponding bit in this register gets set. Reading this register clears all interrupts. This will also reset the IRQ pin if it was configured.

Writing to this register has no effect.

PULLENSET (0x0B, 32 bits, Write Only)

Writing a 1 to any bit in this register enables the internal pullup or pulldown on the corresponding pin. The pull direction (up/down) is determined by the GPIO (output) value - if the corresponding GPIO register bit is low,  its a pulldown. High, its a pullup.

Writing zeros to this register has no effect.

PULLENCLR (0x0C, 32 bits, Write Only)

Writing a 1 to any bit in this register disables the pull up/down on the corresponding pin.

Writing zeros to this register has no effect.

This guide was first published on Oct 20, 2021. It was last updated on 2021-10-20 12:04:17 -0400.

This page (GPIO) was last updated on Oct 04, 2022.

Text editor powered by tinymce.