当前位置:网站首页>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
边栏推荐
- c语言---字符串+内存函数
- Named in pytoch_ parameters、named_ children、named_ Modules function
- R语言中实现作图对象排列的函数总结
- 腾讯Offer已拿,这99道算法高频面试题别漏了,80%都败在算法上
- leetcode-374 猜数字大小
- PS add texture to picture
- Upgrade MySQL 5.1 to 5.69
- Configuration of multi spanning tree MSTP
- Fastjon2他来了,性能显著提升,还能再战十年
- [self entertainment] construction notes week 2
猜你喜欢

Distinct use of spark operator

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

布隆过滤器在亿级流量电商系统的应用

Codejock Suite Pro v20.3.0

For examination

c语言---字符串+内存函数

负载均衡器

Spark 算子之partitionBy

Import address table analysis (calculated according to the library file name: number of imported functions, function serial number and function name)

C语言自编字符串处理函数——字符串分割、字符串填充等
随机推荐
New developments: new trends in cooperation between smartmesh and meshbox
多生成树MSTP的配置
Pgpool II 4.3 Chinese Manual - introductory tutorial
How important is the operation and maintenance process? I heard it can save 2 million a year?
为啥禁用外键约束
c语言---字符串+内存函数
MySQL Cluster Mode and application scenario
保姆级Anaconda安装教程
C, calculation method and source program of bell number
实现缺省页面
Redis master-slave replication process
Deletes the least frequently occurring character in the string
CAP定理
Best practices of Apache APIs IX high availability configuration center based on tidb
Spark 算子之交集、并集、差集
MetaLife与ESTV建立战略合作伙伴关系并任命其首席执行官Eric Yoon为顾问
Go语言数组,指针,结构体
Distinct use of spark operator
Redis主从复制过程
Multi level cache usage