Tuesday, March 10, 2015

ESP201 dev board - One more finding #2.



Perfect ! The last piece of puzzle was found. How to control the relay on the ESP201 development board.

The on board relay is connected to DIP J, and to GPIO16. In order to trigger GPIO16 you need the function from gpio16.c from IoT Demo.


#include "ets_sys.h"#include "osapi.h"#include "driver/gpio16.h"
void ICACHE_FLASH_ATTRgpio16_output_conf(void){    WRITE_PERI_REG(PAD_XPD_DCDC_CONF,                   (READ_PERI_REG(PAD_XPD_DCDC_CONF) & 0xffffffbc) | (uint32)0x1); // mux configuration for XPD_DCDC to output rtc_gpio0
    WRITE_PERI_REG(RTC_GPIO_CONF,                   (READ_PERI_REG(RTC_GPIO_CONF) & (uint32)0xfffffffe) | (uint32)0x0); //mux configuration for out enable
    WRITE_PERI_REG(RTC_GPIO_ENABLE,                   (READ_PERI_REG(RTC_GPIO_ENABLE) & (uint32)0xfffffffe) | (uint32)0x1); //out enable}
void ICACHE_FLASH_ATTRgpio16_output_set(uint8 value){    WRITE_PERI_REG(RTC_GPIO_OUT,                   (READ_PERI_REG(RTC_GPIO_OUT) & (uint32)0xfffffffe) | (uint32)(value & 1));}
void ICACHE_FLASH_ATTRgpio16_input_conf(void){    WRITE_PERI_REG(PAD_XPD_DCDC_CONF,                   (READ_PERI_REG(PAD_XPD_DCDC_CONF) & 0xffffffbc) | (uint32)0x1); // mux configuration for XPD_DCDC and rtc_gpio0 connection
    WRITE_PERI_REG(RTC_GPIO_CONF,                   (READ_PERI_REG(RTC_GPIO_CONF) & (uint32)0xfffffffe) | (uint32)0x0); //mux configuration for out enable
    WRITE_PERI_REG(RTC_GPIO_ENABLE,                   READ_PERI_REG(RTC_GPIO_ENABLE) & (uint32)0xfffffffe); //out disable}
uint8 ICACHE_FLASH_ATTRgpio16_input_get(void){    return (uint8)(READ_PERI_REG(RTC_GPIO_IN_DATA) & 1);}

and the h file.

#ifndef __GPIO16_H__#define __GPIO16_H__
void gpio16_output_conf(void);void gpio16_output_set(uint8 value);void gpio16_input_conf(void);uint8 gpio16_input_get(void);
#endif


Now, during the init gpio part I can call the gpio16_output_conf to setup the GPIO16 as an output GPIO type.

Programmatic now I can call gpio16_output_set (0) or gpio16_output_set(1) to trigger the onboard realy OFF or ON. 

Again, this is the board I am using for testing and development.



1 comment:

  1. Great blog which helped me already a lot.
    I don't get this gpio16 running/compiled.
    Can you tell from where exactly you copied the .c and the .h file?
    And which headers did you exactly include in your .ino?

    When I try to compile, I always get:
    In file included from RelaisOnly.ino:5:0:
    /home/t/Arduino/libraries/DevboardRelais/gpio16ff.h:10:24: error: variable or field 'gpio16_output_set' declared void
    void gpio16_output_set(uint8 value);
    ^
    /home/t/Arduino/libraries/DevboardRelais/gpio16ff.h:10:24: error: 'uint8' was not declared in this scope
    /home/t/Arduino/libraries/DevboardRelais/gpio16ff.h:12:1: error: 'uint8' does not name a type
    uint8 gpio16_input_get(void);
    ^
    Error compiling.


    I copied all from here:
    https://github.com/espressif/ESP8266_RTOS_SDK/blob/master/examples/driver_lib/driver/gpio.c
    also the .h file and put it in one folder.
    I also tried to include #include "stdint.h" in my .ino file but it didn't helped.
    Maybe you could publish all your 3 files which you used.

    Cheers
    Tim

    ReplyDelete