We have often had inquiries from users on how to use the Aardvark I2C/SPI Host Adapter to service interrupts. While the Aardvark adapter does not have pins dedicated for interrupts, it is possible to use the GPIO feature as a workaround to mimic this feature in Aardvark adapters with firmware v3.30 and above.


This approach is possible if the Aardvark adapter is used for only I2C or only SPI operation because the unused bank of pins can be used as GPIO. If both I2C and SPI are required simultaneously, it is not possible to use the method without using a second Aardvark adapter.

In v3.30 of the software, the function aa_gpio_change was added to the API. This function will block until there is a change on the input GPIO lines or the function times out. Using this function it is possible to use any GPIO pin as an interrupt.

The following C code snippet demonstrates how this function is normally used:

// Demonstrate use of aa_gpio_change aa_gpio_direction(handle, 0x00); u08 oldval = aa_gpio_get(handle); printf("Calling aa_gpio_change for 2 seconds...\n"); u08 newval = aa_gpio_change(handle, 2000); if (newval != oldval)   printf("  GPIO inputs changed.\n"); else   printf("  GPIO inputs did not change.\n"); 

The function aa_gpio_change takes two arguments: the handle to the Aardvark adapter and a timeout in milliseconds. When a change occurs on the GPIO lines or the timeout elapses, the function will return the current value of the GPIO lines. It is important that the code stores the old value of the GPIO lines for comparison. Additional details about this function and the GPIO capabilities of the Aardvark adapter can be found in the Aardvark adapter user manual.

The code snippet above was taken from the aagpio.c example. The complete example is included in the Aardvark Software API.