当前位置:网站首页>ESP32_Arduino
ESP32_Arduino
2022-04-23 15:54:00 【Sola_Ex】
ESP32_Arduino
ESP32 GPIO的配置
从乐鑫官方提供的手册来看,ESP32的GPIO基本上是通用型GPIO,也就是除了几个引脚特殊之外,基本上每个引脚都可以使用复用为各种功能,比如SPI/I2C等等。
-
请注意,GPIO6-11通常用于SPI闪存。
-
GPIO34-39只能设置为输入模式,没有软件上拉或下拉功能。
-
还提供了单独的“ RTC GPIO”支持,当GPIO路由到“ RTC”低功耗和模拟子系统时,该支持便起作用。这些引脚功能可在以下情况下使用:
- 在深度睡眠中
- 在超低功耗协处理器运行
- 模拟功能如ADC / DAC /等正在使用中。
以上这段是来自乐鑫官方API教程。
对于ESP32 SDK来说,包含GPIO相关的包含在gpio.c/gpio.h上,相关函数的使用与普通的STM32或NXP的库大同小异。
ESP32 GPIO_Arduino
Arduino是一套硬件抽象好的库,基于SDK的基础上,让各种初始化函数做了一次统一封装,将接口标准化。事实上只需要知道有什么相关的API可以调用就可以了。
常用的API函数有:
- 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可以让GPIO初始化成需要的模式,比如输入/输出等。
//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
对于GPIO来说,单纯的输入输出是不够的的,还需要配合中断来使用,所以Arduino提供了一下的中断模式可选。
//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
对于另外的复用,也提供另外的函数:
#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://blog.csdn.net/qq_42312125/article/details/112762155
边栏推荐
- 腾讯Offer已拿,这99道算法高频面试题别漏了,80%都败在算法上
- [open source tool sharing] MCU debugging assistant (oscillograph / modification / log) - linkscope
- WPS品牌再升级专注国内,另两款国产软件低调出国门,却遭禁令
- gps北斗高精度卫星时间同步系统应用案例
- Temporal model: long-term and short-term memory network (LSTM)
- Leetcode-396 rotation function
- Modèle de Cluster MySQL et scénario d'application
- 多线程原理和常用方法以及Thread和Runnable的区别
- 提取不重复的整数
- Upgrade MySQL 5.1 to 5.68
猜你喜欢

多生成树MSTP的配置

How can poor areas without networks have money to build networks?

WPS brand was upgraded to focus on China. The other two domestic software were banned from going abroad with a low profile

Spark 算子之coalesce与repartition

APISIX jwt-auth 插件存在错误响应中泄露信息的风险公告(CVE-2022-29266)

Cookie&Session
![[AI weekly] NVIDIA designs chips with AI; The imperfect transformer needs to overcome the theoretical defect of self attention](/img/bf/2b4914276ec1083df697383fec8f22.png)
[AI weekly] NVIDIA designs chips with AI; The imperfect transformer needs to overcome the theoretical defect of self attention

大厂技术实现 | 行业解决方案系列教程

使用 Bitnami PostgreSQL Docker 镜像快速设置流复制集群

Multi level cache usage
随机推荐
[open source tool sharing] MCU debugging assistant (oscillograph / modification / log) - linkscope
MySQL - MySQL查询语句的执行过程
幂等性的处理
计算某字符出现次数
Spark 算子之groupBy使用
New developments: new trends in cooperation between smartmesh and meshbox
5 minutes, turn your excel into an online database, the magic cube net table Excel database
C, calculation method and source program of bell number
The length of the last word of the string
Config组件学习笔记
腾讯Offer已拿,这99道算法高频面试题别漏了,80%都败在算法上
Application of Bloom filter in 100 million flow e-commerce system
Temporal model: long-term and short-term memory network (LSTM)
Neodynamic Barcode Professional for WPF V11.0
dlopen/dlsym/dlclose的简单用法
Use bitnami PostgreSQL docker image to quickly set up stream replication clusters
gps北斗高精度卫星时间同步系统应用案例
【第5节 if和for】
Date date calculation in shell script
Extract non duplicate integers