当前位置:网站首页>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
边栏推荐
- API IX JWT auth plug-in has an error. Risk announcement of information disclosure in response (cve-2022-29266)
- utils. Deprecated in35 may be cancelled due to upgrade. What should I do
- 删除字符串中出现次数最少的字符
- Coalesce and repartition of spark operators
- Codejock Suite Pro v20. three
- dlopen/dlsym/dlclose的简单用法
- Go language, condition, loop, function
- JS regular determines whether the port path of the domain name or IP is correct
- 运维流程有多重要,听说一年能省下200万?
- 建设星际计算网络的愿景
猜你喜欢
Load Balancer
Application of Bloom filter in 100 million flow e-commerce system
5 minutes, turn your excel into an online database, the magic cube net table Excel database
MySQL集群模式與應用場景
多线程原理和常用方法以及Thread和Runnable的区别
Coalesce and repartition of spark operators
负载均衡器
运维流程有多重要,听说一年能省下200万?
Unity Shader学习
【现代电子装联期末复习要点】
随机推荐
Calculate the number of occurrences of a character
CAP定理
[self entertainment] construction notes week 2
One brush 312 - simple repetition set - Sword finger offer 03 Duplicate number in array (E)
js正则判断域名或者IP的端口路径是否正确
dlopen/dlsym/dlclose的简单用法
Temporal model: long-term and short-term memory network (LSTM)
MySQL集群模式与应用场景
API IX JWT auth plug-in has an error. Risk announcement of information disclosure in response (cve-2022-29266)
Why disable foreign key constraints
R语言中实现作图对象排列的函数总结
删除字符串中出现次数最少的字符
c语言---指针进阶
WPS brand was upgraded to focus on China. The other two domestic software were banned from going abroad with a low profile
What if the server is poisoned? How does the server prevent virus intrusion?
保姆级Anaconda安装教程
怎么看基金是不是reits,通过银行购买基金安全吗
How important is the operation and maintenance process? I heard it can save 2 million a year?
Go language, array, pointer, structure
shell_ two