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:
Functions:
Setting Pin 1 to logic low
Setting Pin 4 to logic low
Output:
Pin 1 is low
Pin 4 is low
Functions:
Setting Pin 1 to logic high
Setting Pin 4 to logic high
Output:
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 Aret = km_acquire(km, KM_FEATURE_CAN_A_CONFIG |
KM_FEATURE_CAN_A_CONTROL |
KM_FEATURE_CAN_A_LISTEN |
KM)
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.
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
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.