当前位置:网站首页>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
边栏推荐
- 为啥禁用外键约束
- Do we media make money now? After reading this article, you will understand
- 一文掌握vscode远程gdb调试
- Filter usage of spark operator
- Calculate the number of occurrences of a character
- pywintypes. com_ Error: (- 2147221020, 'invalid syntax', none, none)
- Upgrade MySQL 5.1 to 5.611
- MetaLife与ESTV建立战略合作伙伴关系并任命其首席执行官Eric Yoon为顾问
- Leetcode-396 rotation function
- Why disable foreign key constraints
猜你喜欢
Intersection, union and difference sets of spark operators
Spark 算子之coalesce与repartition
一文掌握vscode远程gdb调试
Spark 算子之partitionBy
运维流程有多重要,听说一年能省下200万?
王启亨谈Web3.0与价值互联网“通证交换”
pgpool-II 4.3 中文手册 - 入门教程
MySQL Cluster Mode and application scenario
Spark 算子之filter使用
Large factory technology implementation | industry solution series tutorials
随机推荐
Interview questions of a blue team of Beijing Information Protection Network
一刷312-简单重复set-剑指 Offer 03. 数组中重复的数字(e)
Config learning notes component
实现缺省页面
R语言中实现作图对象排列的函数总结
How can poor areas without networks have money to build networks?
Cookie&Session
Control structure (I)
王启亨谈Web3.0与价值互联网“通证交换”
计算某字符出现次数
Temporal model: long-term and short-term memory network (LSTM)
How do you think the fund is REITs? Is it safe to buy the fund through the bank
Cap theorem
Merging of Shanzhai version [i]
Modèle de Cluster MySQL et scénario d'application
C language --- string + memory function
MySQL集群模式与应用场景
leetcode-374 猜数字大小
Neodynamic Barcode Professional for WPF V11.0
Deletes the least frequently occurring character in the string