Which Aardvark I2C/SPI Host Adapter Pins Can Be Made Available for GPIO Signals and How Are They Controlled?

Question from the Customer:

I am starting to use the Aardvark I2C/SPI Host Adapter and I have some questions about the GPIO pins, including how to program them with your software. I am using the Aardvark adapter with an I2C device.

  • Can you provide guidelines for configuring Aardvark adapter's MISO pin as an output and setting the logic level?
  • For GPIO direction control, I only want to control pins 5 and 7-9, and leave pins 1 and 2 for normal operation. However, my understanding is the aa_gpio_direction function requires an output for pin 1 and pin 2. How can I achieve this or is there another setting to use that does not interfere with normal I2C bus operations?

Response from Technical Support:

Overview of Aardvark Adapter Signal Pins

The Aardvark I2C/SPI Host Adapter is compatible with both 3.3V and 5V signal levels out of the box. The I2C bus is open-drain and the Aardvark adapter contains pull-up resistors for the SCL and SDA lines. These lines are pulled up to 3.3V. We will go over controlling the signals using Aardvark Software API.

Programmable GPIO Pins

The Aardvark GPIO mode has six GPIO signals:

  • Pin 1 - GPIO SCL signal
  • Pin 3 - GPIO SDA signal
  • Pin 5 - GPIO MISO signal
  • Pin 7 - GPIO SCK signal
  • Pin 8 - GPIO MOSI signal
  • Pin 9 - GPIO SS signal

Which pins you can program is related to which mode the Aardvark adapter is enabled in:

  • When the Aardvark adapter is enabled in I2C mode, the four SPI pins (pins 5, 7, 8, 9) are used as GPIO pins. These are the pins that you can program with your setup.
  • When the Aardvark adapter is enabled in SPI mode, the two I2C pins (pin 1 and 3) are used as GPIO pins.
  • In addition to enabling the Aardvark adapter for I2C or SPI modes, there is also a GPIO only mode. In this setting, both SPI and I2C pins are available as GPIO, for a total of six pins.

For example, enabling the Aardvark adapter in I2C mode via aa_configure(handle, AA_CONFIG_GPIO_I2C) allows SPI pins 5, 7, 8 and 9 to be controlled with API calls. The I2C signal pins cannot be used as GPIO pins.

Aardvark Adapter Signals per Mode

I2C Mode Pins:

  • SCL (Pin 1): Serial Clock line
  • SDA (Pin 3): Serial Data line

SPI Mode Pins:                                                                    

  • SCLK (Pin 7): Serial Clock
  • MOSI (Pin 8): Master Out Slave In
  • MISO (Pin 5): Master In Slave Out
  • SS (Pin 9): Slave Select

GPIO Mode Pins:

  • In GPIO mode, all six of the above I2C and SPI pins are available as GPIO pins.

Setting I/O Logic Levels

GPIO pins can be configured for input signals or output signals. For input signals, the internal pull-ups can be enabled for disabled.

  • When a GPIO bit is configured as an input, the signal pull-up can be enabled or disabled.
  • If GPIO bit is configured as an output, and the value 1 is writing to that bit, then the signal will be logic 1.
  • If GPIO bit is configured as an output, and the value 0 is writing to that bit, then the signal will be logic 0.
  • If GPIO bit is configured as an input, and logic 1 is supplied to the signal, then the bit is read logic 1.
  • If GPIO bit is configured as an input, and logic 0 is supplied to the signal, then the bit is read logic 0.

Configuring GPIO Pins using API

When using the handle aa_configure(handle, AA_CONFIG_GPIO_I2C),  the Aardvark adapter is set with GPIO+I2C configuration in which the SPI pins (pins 5, 7, 8, 9) are used as GPIO pins (GPIO# 02, 03, 04, 05).

The table below shows the corresponding GPIO number, pin number, and value. Please note, all six pins that could be used as GPIO are listed. The pins that apply for your I2C configuration are 5, 7, 8, and 9.

Table of the mask values per GPIO pin GPIO Pinout and Mask Values

The values are assigned per bitmasks of six GPIO pins starting from GPIO00 to GPIO05.

Programming Pin I/O with Bitmasks

Setting Direction:

print aa_gpio_direction(handle,0x0C)

For setting direction, when a line's bit is 0, the line is configured as an input. Otherwise, that will be an output. The value passed is 0x0C which sets GPIO00 and GPIO01 as input lines; this is not valid as these are I2C lines, not GPIO lines. Other available GPIOs (GPIO04 and GPIO05) are inputs. GPIO02 and GPIO03 are configured as output lines.

Setting Logic:

aa_gpio_set(handle,0x0C)

The 0x0C value is a bitmask that specifies which outputs are set to logic high and which outputs are set to logic low. With the value 0x0C, GPIO# 02 and GPIO# 03 are set to logic high.

We hope this answers your questions. Additional resources that you may find helpful include the following:

If you need more information, feel free to contact us with your questions, or request a demo that applies to your application.

Request a Demo