Q: How do I program the GPIO? Do you have an example?

ESP_Luna

Q: How do I program the GPIO? Do you have an example?

Postby ESP_Luna » Tue Jul 28, 2015 1:03 pm

Q: How do I program the GPIO? Do you have an example?
Difference exists between non-OS and OS version in the programming process.
[Non-OS Version]
Set the input mode to MTDO and configure it in falling edge trigger mode.

Code: Select all

void ICACHE_FLASH_ATTR gpio_init(void)
{
    PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDO_U,FUNC_GPIO15);                //GPIO Alternate Function
    GPIO_DIS_OUTPUT(GPIO_ID_PIN(15));                                  //Configure it in input mode.
    ETS_GPIO_INTR_DISABLE();                                           //Close the GPIO interrupt
    ETS_GPIO_INTR_ATTACH(GPIO_INTERRUPT,NULL);                         //Register the interrupt function
    gpio_pin_intr_state_set(GPIO_ID_PIN(15),GPIO_PIN_INTR_NEGEDGE);    //Falling edge trigger
    ETS_GPIO_INTR_ENABLE() ;                                           //Enable the GPIO interrupt
}

[OS Version]
Set the input mode to MTDO and configure it in falling edge trigger mode.
void ICACHE_FLASH_ATTR gpio_init(void)

Code: Select all

{
    GPIO_ConfigTypeDef gpio_in_cfg;                                    //Define GPIO Init Structure
    gpio_in_cfg.GPIO_IntrType = GPIO_PIN_INTR_NEGEDGE;                 //Falling edge trigger
    gpio_in_cfg.GPIO_Mode = GPIO_Mode_Input;                           //Input mode
    gpio_in_cfg.GPIO_Pin  = GPIO_Pin_15;                               // Enable GPIO
    gpio_config(&gpio_in_cfg);                                         //Initialization function
    GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(GPIO_UART_IN_NUM));
    gpio_intr_handler_register(interrupt_GPIO_UART);                   // Register the interrupt function
    _xt_isr_unmask(1 << ETS_GPIO_INUM);                                //Enable the GPIO interrupt
}

[Configuration Instructions]
Please refer to "0D-ESP8266__Pin_List__Release_15-11-2014.xlsx" in the Documentation List of Development Guides.
  • You can refer to GPIO alternate function registers in the Reg tabs.
  • You can refer to GPIO and its multiplexing functions in the Digital Die Pin List tabs, during which the column of FUNCTION provides configuration options for functions.
    Type 2 in the corresponding bit of the register if it’s needed to configure it in FUNCTION3; type 1 in the corresponding bit if it’s needed to configure it in FUNCTION2, and so on.
    For example, in the code of PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDO_U,FUNC_GPIO15), the value of FUNC_GPIO15 is three and according to FUNCTION4 in the list, this means that PERIPHS_IO_MUX_MTDO_U is configured to GPIO function.

Who is online

Users browsing this forum: No registered users and 125 guests