SENSOR_CAPN and SENSOR_VN pin used as external interrupt pins
Posted: Fri Mar 17, 2017 2:32 am
I want to use SENSOR_CAPN and SENSOR_VN pins to act as external interrupt pins to read a rotary dial. SENSOR_CAPN is ok, but SENSOR_VN always trigger the interrupt even the pin does not change state. Is it relate to the ADC_PRE_AMP function? Below is my code:
// Rotary encoder
#define PIN_ROT_A 38 /* SENSOR_CAPN */
#define PIN_ROT_B 39 /* SENSOR_VN */
static QueueHandle_t q1;
#if (PIN_ROT_A >= 0)
static void rota(void *arg) {
gpio_num_t gpio = PIN_ROT_A;
xQueueSendToBackFromISR(q1, &gpio, NULL);
}
#endif
#if (PIN_ROT_B >= 0)
static void rotb(void *arg) {
gpio_num_t gpio = PIN_ROT_B;
xQueueSendToBackFromISR(q1, &gpio, NULL);
}
#endif
void app_main() {
esp_err_t ret;
gpio_config_t gpioConfig;
q1 = xQueueCreate(10, sizeof(gpio_num_t));
gpio_install_isr_service(0);
gpioConfig.mode = GPIO_MODE_INPUT;
gpioConfig.pull_up_en = GPIO_PULLUP_ENABLE;
gpioConfig.pull_down_en = GPIO_PULLDOWN_DISABLE;
gpioConfig.intr_type = GPIO_INTR_ANYEDGE;
#if (PIN_ROT_A >= 0)
gpioConfig.pin_bit_mask = 1ULL << PIN_ROT_A;
ret = gpio_config(&gpioConfig);
assert(ret == ESP_OK);
gpio_set_direction(PIN_ROT_A, GPIO_MODE_INPUT);
gpio_isr_handler_add(PIN_ROT_A, rota, NULL );
#endif
#if (PIN_ROT_B >= 0)
gpioConfig.pin_bit_mask = 1ULL << PIN_ROT_B;
ret = gpio_config(&gpioConfig);
assert(ret == ESP_OK);
gpio_set_direction(PIN_ROT_B, GPIO_MODE_INPUT);
gpio_isr_handler_add(PIN_ROT_B, rotb, NULL );
#endif
while(1) {
gpio_num_t gpio;
ESP_LOGI(tag, "Waiting on interrupt queue");
BaseType_t rc = xQueueReceive(q1, &gpio, portMAX_DELAY);
ESP_LOGI(tag, "Woke from interrupt queue wait: %d, gpio=%d", rc, gpio);
}
}
Colman
// Rotary encoder
#define PIN_ROT_A 38 /* SENSOR_CAPN */
#define PIN_ROT_B 39 /* SENSOR_VN */
static QueueHandle_t q1;
#if (PIN_ROT_A >= 0)
static void rota(void *arg) {
gpio_num_t gpio = PIN_ROT_A;
xQueueSendToBackFromISR(q1, &gpio, NULL);
}
#endif
#if (PIN_ROT_B >= 0)
static void rotb(void *arg) {
gpio_num_t gpio = PIN_ROT_B;
xQueueSendToBackFromISR(q1, &gpio, NULL);
}
#endif
void app_main() {
esp_err_t ret;
gpio_config_t gpioConfig;
q1 = xQueueCreate(10, sizeof(gpio_num_t));
gpio_install_isr_service(0);
gpioConfig.mode = GPIO_MODE_INPUT;
gpioConfig.pull_up_en = GPIO_PULLUP_ENABLE;
gpioConfig.pull_down_en = GPIO_PULLDOWN_DISABLE;
gpioConfig.intr_type = GPIO_INTR_ANYEDGE;
#if (PIN_ROT_A >= 0)
gpioConfig.pin_bit_mask = 1ULL << PIN_ROT_A;
ret = gpio_config(&gpioConfig);
assert(ret == ESP_OK);
gpio_set_direction(PIN_ROT_A, GPIO_MODE_INPUT);
gpio_isr_handler_add(PIN_ROT_A, rota, NULL );
#endif
#if (PIN_ROT_B >= 0)
gpioConfig.pin_bit_mask = 1ULL << PIN_ROT_B;
ret = gpio_config(&gpioConfig);
assert(ret == ESP_OK);
gpio_set_direction(PIN_ROT_B, GPIO_MODE_INPUT);
gpio_isr_handler_add(PIN_ROT_B, rotb, NULL );
#endif
while(1) {
gpio_num_t gpio;
ESP_LOGI(tag, "Waiting on interrupt queue");
BaseType_t rc = xQueueReceive(q1, &gpio, portMAX_DELAY);
ESP_LOGI(tag, "Woke from interrupt queue wait: %d, gpio=%d", rc, gpio);
}
}
Colman