How to toggle GPIO Pin?

Stational
Posts: 42
Joined: Sat Jul 02, 2016 10:54 pm

How to toggle GPIO Pin?

Postby Stational » Sun Nov 20, 2016 5:49 am

Hi,

i am wondering why my code doesn't work:

Code: Select all

#include <osapi.h>
#include <ets_sys.h>
#include <gpio.h>
#include "user_interface.h"
#include "eagle_soc.h"

os_timer_t timer;

void toggleGPIO(void){
    if (GPIO_REG_READ(GPIO_OUT_ADDRESS) & BIT10)
    {
        gpio_output_set(0, BIT10, BIT10, 0);
        os_printf("SET BIT10 to low.\n");
    }
    else
    {
        gpio_output_set(BIT10, 0, BIT10, 0);
        os_printf("SET BIT10 to high.\n");
    }
}

void user_init(void){
   os_timer_setfn(&timer,(os_timer_func_t*)toggleGPIO,NULL);
   os_timer_arm(&timer,1000,1);
}


I get alternating "SET BIT10 to high" and "SET BIT10 to low" on my serial console but in reality, GPIO10 is high all the time and never low. Why is that?

pratik

Re: How to toggle GPIO Pin?

Postby pratik » Sun Nov 27, 2016 1:51 pm

Please go through the documentation carefully. You have skipped a function to mark the GPIO as an output. For example,

Code: Select all

PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDI_U, FUNC_GPIO12); // Use MTDI pin as GPIO12.


GPIO names for your easy reference:
GPIO0: PERIPHS_IO_MUX_GPIO0_U
GPIO1: PERIPHS_IO_MUX_U0TXD_U
GPIO2: PERIPHS_IO_MUX_GPIO2_U
GPIO3: PERIPHS_IO_MUX_U0RXD_U
GPIO4: PERIPHS_IO_MUX_GPIO4_U
GPIO5: PERIPHS_IO_MUX_GPIO5_U
GPIO6: PERIPHS_IO_MUX_SD_CLK_U
GPIO7: PERIPHS_IO_MUX_SD_DATA0_U
GPIO8: PERIPHS_IO_MUX_SD_DATA1_U
GPIO9: PERIPHS_IO_MUX_SD_DATA2_U
GPIO10: PERIPHS_IO_MUX_SD_DATA3_U
GPIO11: PERIPHS_IO_MUX_SD_CMD_U
GPIO12: PERIPHS_IO_MUX_MTDI_U
GPIO13: PERIPHS_IO_MUX_MTCK_U
GPIO14: PERIPHS_IO_MUX_MTMS_U
GPIO15: PERIPHS_IO_MUX_MTDO_U

Who is online

Users browsing this forum: No registered users and 58 guests