I2C SPI USB CAN eSPI Cable Testing View All Videos Quick Start Guides Software Downloads App Notes White Papers User Manuals Knowledge Base Sales Support About Us
Products Blog Sales Support Contact Search
How Do I Configure GPIO Pins Using the Komodo Software API?
Rena Ayeras

Question from the Customer:

I am using a Komodo CAN Duo Interface with the Komodo Software API. I am trying to control the GPIO pins for output signals. I think I have done everything necessary, but the GPIO pins are not responding as expected. With my program, pin 4 stays low like this:


Setting Pin 1 to logic low

Setting Pin 4 to logic low


Pin 1 is low

Pin 4 is low


Setting Pin 1 to logic high

Setting Pin 4 to logic high


Pin 1 is high

Pin 4 is low

I used the Total Phase example file gpio.py and made some changes for the functions I need. Here are sections of the code used for setting up the Komodo interface and configuring the GPIO:

# Acquire features to control and listen CAN A

ret = km_acquire(km, KM_FEATURE_CAN_A_CONFIG  |




print('\nSetting Pin 1 to logic High')

km_gpio_set(km, 1, KM_GPIO_PIN_1_MASK)

print('\nSetting Pin 4 to logic High')

km_gpio_set(km, 1, KM_GPIO_PIN_4_MASK)

Can you take a look and tell me what I left out or need to change?

Response from Technical Support:

Thanks for your question! Your challenge is with the API call int km_gpio_set (Komodo komodo, u08 value, u08 mask), and it’s very easy to fix. Both the value and the mask are bit fields. We’ll provide some details about the values, followed with an example of what is needed to make your program work.

GPIO Configuration and Mask Fields

Here are the values of the parameters for int km_gpio_set(), which were extracted from the header files:

/* GPIO Configuration */

#define KM_GPIO_PIN_1_CONFIG 0x00

#define KM_GPIO_PIN_2_CONFIG 0x01

#define KM_GPIO_PIN_3_CONFIG 0x02

#define KM_GPIO_PIN_4_CONFIG 0x03

#define KM_GPIO_PIN_5_CONFIG 0x04

#define KM_GPIO_PIN_6_CONFIG 0x05

#define KM_GPIO_PIN_7_CONFIG 0x06

#define KM_GPIO_PIN_8_CONFIG 0x07

/* GPIO Mask */

#define KM_GPIO_PIN_1_MASK 0x01

#define KM_GPIO_PIN_2_MASK 0x02

#define KM_GPIO_PIN_3_MASK 0x04

#define KM_GPIO_PIN_4_MASK 0x08

#define KM_GPIO_PIN_5_MASK 0x10

#define KM_GPIO_PIN_6_MASK 0x20

#define KM_GPIO_PIN_7_MASK 0x40

#define KM_GPIO_PIN_8_MASK 0x80

Mask for GPIO

To turn on GPIO pin 4, what you have is:

km_gpio_set(km, 1, KM_GPIO_PIN_4_MASK)

All you need to do is add the mask as shown below:

km_gpio_set(km, KM_GPIO_PIN_4_MASK, KM_GPIO_PIN_4_MASK)

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

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

Request a Demo