Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

Switch doesn't set on/off. It is always high.

sI am trying to turn on or off switch. When I measue voltage on feet of the switch it is always 3.3V. There is no change. I am setting pin on or off and I get state of pin by gpio_pin_get() function. 

I can see diffrence between pin and pin_1 but switch doesnt change.

#define SWTCH_NODE DT_ALIAS(swtch0)
#define SWTCH     DT_GPIO_LABEL(SWTCH_NODE, gpios)
#define SWTCHPIN   DT_GPIO_PIN(SWTCH_NODE, gpios)
#define FLAGS        DT_GPIO_FLAGS(SWTCH_NODE, gpios)

static const struct device *dev;
int err;
int ret;
int pin;
int pin_1;
/**
* @brief TIM application task function.
*/
static void Battery(void)
{  
    uint16_t batData;
    uint16_t socData;
    uint16_t sohData;
    uint16_t avData;
    dev = device_get_binding(SWTCH);
    ret = gpio_pin_configure(dev, SWTCHPIN, GPIO_OUTPUT| FLAGS);
    err=gpio_pin_set(dev, SWTCHPIN, 1);
    pin=gpio_pin_get(dev,SWTCHPIN);
    LOG_INF("pin::%d",pin);
    k_msleep(1000);
    err=gpio_pin_set(dev, SWTCHPIN,0);
    pin_1=gpio_pin_get(dev,SWTCHPIN);
    LOG_INF("pin::%d",pin_1);
    k_msleep(1000);
}
OVERLAY FILE
/ {
       
    i2c-switch {
        compatible = "gpio-leds";
        swtch0: swtch_0 {
            gpios = <&gpio0 14 (GPIO_ACTIVE_LOW)>;
            label = "I2C switch";
        };
    };
   
    aliases {
        swtch0=&swtch0;
    };  
   
};
Related