当前位置:网站首页>ESP32_ Arduino

ESP32_ Arduino

2022-04-23 15:55:00 Sola_ Ex

ESP32_Arduino

ESP32 GPIO Configuration of

From the official manual provided by Lexin ,ESP32 Of GPIO Basically universal GPIO, That is, except for a few special pins , Basically, each pin can be multiplexed into various functions , such as SPI/I2C wait .

  • Please note that ,GPIO6-11 Usually used for SPI Flash memory .

  • GPIO34-39 Can only be set to input mode , There is no software pull-up or pull-down function .

  • A separate “ RTC GPIO” Support , When GPIO Route to “ RTC” Low power consumption and analog subsystem , That support works . These pin functions can be used in the following cases :

The above paragraph is from the official of Lexin API course .

about ESP32 SDK Come on , contain GPIO Related are contained in gpio.c/gpio.h On , The use of correlation functions is similar to that of ordinary STM32 or NXP Our library is similar .

ESP32 GPIO_Arduino

Arduino It is a good set of hardware abstraction Library , be based on SDK On the basis of , Let all kinds of initialization functions do a unified encapsulation , Standardize interfaces . In fact, you just need to know what's relevant API Just call it .

frequently-used API Function has :

  • pinMode(uint8_t pin, uint8_t mode)
  • digitalWrite(uint8_t pin, uint8_t val)
  • digitalRead(uint8_t pin)
  • attachInterrupt(uint8_t pin, void ()(void), int mode);
  • attachInterruptArg(uint8_t pin, void ()(void), void * arg, int mode);
  • detachInterrupt(uint8_t pin);

pinMode It can make GPIO Initialize to the required mode , Such as input / Output, etc .

//GPIO FUNCTIONS
#define INPUT 0x01
#define OUTPUT 0x02
#define PULLUP 0x04
#define INPUT_PULLUP 0x05
#define PULLDOWN 0x08
#define INPUT_PULLDOWN 0x09
#define OPEN_DRAIN 0x10
#define OUTPUT_OPEN_DRAIN 0x12
#define SPECIAL 0xF0
#define FUNCTION_1 0x00
#define FUNCTION_2 0x20
#define FUNCTION_3 0x40
#define FUNCTION_4 0x60
#define FUNCTION_5 0x80
#define FUNCTION_6 0xA0
#define ANALOG 0xC0

about GPIO Come on , Simple input and output is not enough , It also needs to be used with interrupts , therefore Arduino The following interrupt mode options are provided .

//Interrupt Modes

#define DISABLED 0x00

#define RISING 0x01

#define FALLING 0x02

#define CHANGE 0x03

#define ONLOW 0x04

#define ONHIGH 0x05

#define ONLOW_WE 0x0C

#define ONHIGH_WE 0x0D

For additional reuse , Additional functions are also provided :

#define digitalPinIsValid(pin) ((pin) < 40 && esp32_gpioMux[(pin)].reg)

#define digitalPinCanOutput(pin) ((pin) < 34 && esp32_gpioMux[(pin)].reg)

#define digitalPinToRtcPin(pin) (((pin) < 40)?esp32_gpioMux[(pin)].rtc:-1)

#define digitalPinToAnalogChannel(pin) (((pin) < 40)?esp32_gpioMux[(pin)].adc:-1)

#define digitalPinToTouchChannel(pin) (((pin) < 40)?esp32_gpioMux[(pin)].touch:-1)

#define digitalPinToDacChannel(pin) (((pin) == 25)?0:((pin) == 26)?1:-1)

版权声明
本文为[Sola_ Ex]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231554163710.html