当前位置:网站首页>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
边栏推荐
- PHP function
- PS add texture to picture
- utils. Deprecated in35 may be cancelled due to upgrade. What should I do
- c语言---字符串+内存函数
- Go language slice, range, set
- APISIX jwt-auth 插件存在错误响应中泄露信息的风险公告(CVE-2022-29266)
- Load Balancer
- How can poor areas without networks have money to build networks?
- Neodynamic Barcode Professional for WPF V11.0
- Leetcode-374 guess the size of the number
猜你喜欢
Pgpool II 4.3 Chinese Manual - introductory tutorial
大型互联网为什么禁止ip直连
Why is IP direct connection prohibited in large-scale Internet
Large factory technology implementation | industry solution series tutorials
Metalife established a strategic partnership with ESTV and appointed its CEO Eric Yoon as a consultant
pgpool-II 4.3 中文手册 - 入门教程
基于 TiDB 的 Apache APISIX 高可用配置中心的最佳实践
为啥禁用外键约束
单体架构系统重新架构
Distinct use of spark operator
随机推荐
PHP classes and objects
pgpool-II 4.3 中文手册 - 入门教程
Deletes the least frequently occurring character in the string
utils. Deprecated in35 may be cancelled due to upgrade. What should I do
IronPDF for . NET 2022.4.5455
Single architecture system re architecture
[open source tool sharing] MCU debugging assistant (oscillograph / modification / log) - linkscope
一文读懂串口及各种电平信号含义
Interview questions of a blue team of Beijing Information Protection Network
Fastjon2他来了,性能显著提升,还能再战十年
[section 5 if and for]
Coalesce and repartition of spark operators
vim指定行注释和解注释
leetcode-374 猜数字大小
String sorting
删除字符串中出现次数最少的字符
Pgpool II 4.3 Chinese Manual - introductory tutorial
s16. One click installation of containerd script based on image warehouse
一刷312-简单重复set-剑指 Offer 03. 数组中重复的数字(e)
Use bitnami PostgreSQL docker image to quickly set up stream replication clusters