Trouble with pin output after analog read

mato157
Posts: 2
Joined: Fri Nov 09, 2018 10:02 am

Trouble with pin output after analog read

Postby mato157 » 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:

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);
    }
}
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.

Who is online

Users browsing this forum: Bing [Bot], BivvyCoder and 95 guests