Trouble with pin output after analog read
Posted: Fri Nov 09, 2018 10:31 am
Hello,
I am working on a program where I need first read analog value from pin then change pin direction and set logic 1 on the same pin.
Here is my test code:
But logical value 1 is not set.
It seems like the problem is with ADC which is initialized to that pin.
So it is possible to somehow deinitialize ADC from pin and use it as out pin? Or some other way how to make this switch between analog input a logical output correctly?
Thank you for your answers.
I am working on a program where I need first read analog value from pin then change pin direction and set logic 1 on the same pin.
Here is my test code:
Code: Select all
#define XL 32
void app_main()
{
uint16_t tempx;
gpio_pad_select_gpio(XL);
adc1_config_width(ADC_WIDTH_10Bit);
while(1) {
printf("XL set as analog input \n");
gpio_set_direction(XL, GPIO_MODE_INPUT);
adc1_config_channel_atten(ADC1_CHANNEL_4, ADC_ATTEN_11db);
tempx = adc1_get_raw(ADC1_CHANNEL_4);
vTaskDelay(5000 / portTICK_PERIOD_MS);
printf("XL set as output with level 1 \n");
gpio_set_direction(XL, GPIO_MODE_OUTPUT);
gpio_set_level(XL, 1);
vTaskDelay(5000 / portTICK_PERIOD_MS);
}
}
It seems like the problem is with ADC which is initialized to that pin.
So it is possible to somehow deinitialize ADC from pin and use it as out pin? Or some other way how to make this switch between analog input a logical output correctly?
Thank you for your answers.