完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我正在尝试使用 MCP23017 扩展 ESP8266(wemos mini D1)的 IO 端口数量。
我正在使用 MCP23017 的 INTA 在 ESP8266 的引脚 D5 上触发中断(如附图所示)。 下面的代码工作正常。当我按下按钮开关时,串行监视器中显示了按下按钮的引脚号。 #include #include "Adafruit_MCP23017.h" Adafruit_MCP23017 mcp; 易失性无符号长 last_interrupt;// 用于存储上次中断的时间(以毫秒为单位),用于去抖动 int debounce_delay = 100; // 按钮按下之间的最小延迟(以毫秒为单位),用于去抖动 易失性 uint8_t pin_num;// 当检测到中断并对其进行解码时,生成中断的引脚存储在此处 volatile uint8_t int_pin_val ; int esp_interrupt_pin=14;// GPIO14 (D5) bool send_to_me; 字节 mcp_PA0=0; void cleanInterrupt(){ while(!(mcp.digitalRead(0))) ; // 现在 MCP 已准备好接收另一个中断 } void ICACHE_RAM_ATTR intCallBack() { pin_num = mcp.getLastInterruptPin(); int_pin_val = mcp.getLastInterruptPinValue(); if(millis()-last_interrupt>=debounce_delay) // 去抖程序 { send_to_me=true; } last_interrupt=millis(); 清洁中断();// 调用清除所有中断寄存器的函数 } void setup() { Serial.begin(115200); pinMode(esp_interrupt_pin,输入); mcp.开始(); mcp.setupInterrupts(假,假,低); mcp.pinMode(mcp_PA0,输入); mcp.pullUp(mcp_PA0,高);// 在内部开启 100K 上拉 mcp.setupInterruptPin(mcp_PA0,CHANGE); 清洁中断();// 调用清除所有中断寄存器的函数 // 这里我们将中断附加到 MCU 引脚,用于侦听来自 mcp 的中断... attachInterrupt(digitalPinToInterrupt(esp_interrupt_pin),intCallBack,FALLING); } 无效循环(){ 如果 (send_to_me==true){ Serial.print("Pin = "); Serial.println(pin_num); 发送给我=假; 然而 当我一直按下按钮而不松开它时,几秒钟后,我会重置看门狗定时器。 ets Jan 8 2013,rst cause:4, boot mode:(3,6) wdt reset load 0x4010f000, len 3584, room 16 tail 0 chksum 0xb0 csum 0xb0 v2843a5ac ~ld 我试图将 yield() 放入循环中但没有解决不了问题。 |
|
相关推荐
|
|
只有小组成员才能发言,加入小组>>
220个成员聚集在这个小组
加入小组547 浏览 1 评论
2462 浏览 2 评论
为blufi_device设置自定义名称,但是无法修改,为什么?
476浏览 4评论
请问ESP32-S2-WROOM怎么获得ESP32-S2外接FLASH的唯一序列号?
252浏览 3评论
ESP-Jumpstart例程中第5个工程:5_cloud连接报错是哪里的问题?
267浏览 2评论
用AT+CIPSNTPCFG=1,8,\"cn.ntp.org.cn\",\"ntp.sjtu.edu.cn\"更新不了时间怎么处理?
702浏览 2评论
361浏览 2评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-4-21 14:57 , Processed in 0.792355 second(s), Total 44, Slave 38 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191