ESP8266 Developer Zone The Official ESP8266 Forum 2020-02-19T06:51:01+08:00 https://bbs.espressif.com:443/feed.php?f=7&t=24977 2020-02-19T06:51:01+08:00 2020-02-19T06:51:01+08:00 https://bbs.espressif.com:443/viewtopic.php?t=24977&p=73587#p73587 <![CDATA[Re: Backing up settings from READ_PERI_REG]]>
GPIO_REG_READ may be what I am looking for.

Statistics: Posted by AgentSmithers — Wed Feb 19, 2020 6:51 am


]]>
2018-12-24T10:27:34+08:00 2018-12-24T10:27:34+08:00 https://bbs.espressif.com:443/viewtopic.php?t=24977&p=36141#p36141 <![CDATA[Backing up settings from READ_PERI_REG]]>
My guess is that I need to call READ_PERI_REG(PIN_NAME) beforehand and store the bitvalues but after reviewing the definition I'm not quite sure. It would be appreciated if anyone had some guidance.
I am using the code below to autodetect which pin the DHT22 is on.

Code:

void AutoDetect()
{
   //This code may need to get the values before setting the Pin_Func_Select to restore after
   //I think the code for Pin_Func_Selct macro is in Eagle_soc.h
   /*
   #define PIN_FUNC_SELECT(PIN_NAME, FUNC)  do { \
   WRITE_PERI_REG(PIN_NAME,         \
        (READ_PERI_REG(PIN_NAME)            \
    &  (~(PERIPHS_IO_MUX_FUNC<<PERIPHS_IO_MUX_FUNC_S))) \
        |  ( (((FUNC&BIT2)<<2)|(FUNC&0x3))<<PERIPHS_IO_MUX_FUNC_S) ); \
   } while (0)
   */
   ThermostatConfig.programmed = 1;
   ThermostatConfig.ThermostatType = MySensor_DHT22;
   ThermostatConfig.PowerMethod = 0;

   int i;

   for(i = 15; i >= 0; i--)
   {
      os_printf("Detecting Therm on GPIO %d", i);
      PIN_FUNC_SELECT(g_pin_muxes[i], g_pin_funcs[i]);
      PIN_PULLUP_EN(g_pin_muxes[i]);
      ThermostatConfig.GPIO = i;
      if (pollDHTData())
      {
         os_printf("Therm Detected on GPIO %d", i);
         return;
      }
      if (i == 12)
      {
         i = 6; //Skip over bad Pins
      }
      if (i == 3)
      {
         i = 1; //Pin 2 and 3 crashes the esp when using this method
      }
   }

   ThermostatConfig.programmed = 0;
   ThermostatConfig.ThermostatType = 0;
   ThermostatConfig.PowerMethod = 0;
}

Statistics: Posted by AgentSmithers — Mon Dec 24, 2018 10:27 am


]]>