Having a bit of an Issue with GPIO21
In essence I am setting GPIO21 to Input and attempting to set it floating, no matter what setting I seem to apply to that particular pin I can only get it to read a change in level when using a less than 780 Ohm resistor in series, i.e. GPIO36 will change no problem even with a 50k R in series , all of the other pins seems to be just fine, not sure what I could be doing wrong to make GPIO21 so difficult to change voltage level on.
I have tried setting the pins as a group and setting them individually, same result each time. Any pointers would be great.
These are the different bits of code I have tried.
Code: Select all
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/event_groups.h"
#include "freertos/queue.h"
#include "esp_system.h"
#include "esp_wifi.h"
#include "esp_event_loop.h"
#include "esp_log.h"
#include "nvs_flash.h"
#include "driver/uart.h"
#include "lwip/err.h"
#include "lwip/sockets.h"
#include "lwip/sys.h"
#include "lwip/netdb.h"
#include "lwip/dns.h"
#include "lwip/pppapi.h"
#include "driver/gpio.h"
#include "BootLoadNXP.h"
#include "freertos/queue.h"
#include "NXPuart_events.h"
#include "driver/adc.h"
#define GPIO_OUTPUT_PIN_SEL (GPIO_SEL_25 | GPIO_SEL_26 | GPIO_SEL_32 | GPIO_SEL_13 | GPIO_SEL_14)
#define GPIO_INPUT_PIN_SEL (GPIO_SEL_36 | GPIO_SEL_21)
#define Tamper GPIO_NUM_36
#define POWER_CHANNEL GPIO_NUM_21
#define ESP_INTR_FLAG_DEFAULT 0
int Set_Pin_Input(int PinNumber)
{
return gpio_set_direction(PinNumber, GPIO_MODE_INPUT);
}
int Set_Pin_Float(int PinNumber)
{
return gpio_set_pull_mode(PinNumber, GPIO_FLOATING);
}
int Set_Pin_PullUp(int PinNumber)
{
return gpio_set_pull_mode(PinNumber, GPIO_PULLUP_ONLY);
}
int Set_Pin_PullDown(int PinNumber)
{
return gpio_set_pull_mode(PinNumber, GPIO_PULLDOWN_ONLY);
}
void app_main()
{
gpio_config_t io_conf;
//disable interrupt
io_conf.intr_type = GPIO_PIN_INTR_DISABLE;
//set as output mode
io_conf.mode = GPIO_MODE_OUTPUT;
//bit mask of the pins that you want to setf,e.g.GPIO18/19
io_conf.pin_bit_mask = GPIO_OUTPUT_PIN_SEL;
//disable pull-down mode
io_conf.pull_down_en = 0;
//disable pull-up mode
io_conf.pull_up_en = 0;
gpio_config(&io_conf); // Works Fine
//disable interrupt
io_conf.intr_type = GPIO_INTR_NEGEDGE;
//set as output mode
io_conf.mode = GPIO_MODE_INPUT;
//bit mask of the pins that you want to setf,e.g.GPIO18/19
io_conf.pin_bit_mask = GPIO_INPUT_PIN_SEL;
//disable pull-down mode
io_conf.pull_down_en = 0;
//disable pull-up mode
io_conf.pull_up_en = 0;
gpio_config(&io_conf);
int n;
n=0;
while(n<10)
{
if (gpio_get_level(Tamper) == 0) printf("TAMPER!!\n");
printf("The Power Level is value:%d\n",gpio_get_level(POWER_CHANNEL));
vTaskDelay(1000 / portTICK_PERIOD_MS);
n++;
}
gpio_pad_select_gpio(Tamper);
if (Set_Pin_Input(Tamper) != ESP_OK) printf("Error Selecting Tamper Pin as Input\n"); //Works FINE
if (Set_Pin_Float(Tamper) != ESP_OK) printf("Error Setting Tamper Pin as Floating\n"); //Works FINE
n=0;
while(n<10)
{
if (gpio_get_level(Tamper) == 0) printf("TAMPER!!\n");
printf("The Power Level is value:%d\n",gpio_get_level(POWER_CHANNEL));
vTaskDelay(1000 / portTICK_PERIOD_MS);
n++;
}
gpio_pad_select_gpio(POWER_CHANNEL);
if (Set_Pin_Input(POWER_CHANNEL) != ESP_OK) printf("Error Selecting POWER INDICATOR Pin as Input\n"); //Seems to Work Fine
if (Set_Pin_Float(POWER_CHANNEL) != ESP_OK) printf("Error Setting POWER INDICATOR Pin as Floating\n"); //Seems to Work Fine
while(1)
{
if (gpio_get_level(Tamper) == 0) printf("TAMPER!!\n");
printf("The Power Level is value:%d\n",gpio_get_level(POWER_CHANNEL));
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}