您好!
CC2640R2F 引脚中断一次后不工作
请提供任何建议。
感谢您
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
您好!
以下是我对您的描述的理解。 您能确认吗? 您是否还能确认此处没有其他组件起作用? 我提出这个问题的原因是、DIO4用于 CC2640R2F LaunchPad 参考设计中的 I2C。
假设我的理解正确、您应该确保启用了内部下拉。
下面是我为你写的一些代码:
#include <unistd.h> /* Driver Header files */ #include <ti/drivers/PIN.h> #include <ti/devices/cc26x0r2/driverlib/ioc.h> /* Example/Board Header files */ #include "Board.h" /* Pin driver handles */ static PIN_Handle buttonPinHandle; /* Global memory storage for a PIN_Config table */ static PIN_State buttonPinState; PIN_Config buttonPinTable[] = { IOID_4 | PIN_GPIO_OUTPUT_DIS | PIN_INPUT_EN | PIN_PULLDOWN | PIN_IRQ_POSEDGE, PIN_TERMINATE }; /* * ======== buttonCallbackFxn ======== */ void buttonCallbackFxn(PIN_Handle handle, PIN_Id pinId) { // Your code } /* * ======== mainThread ======== */ void *mainThread(void *arg0) { buttonPinHandle = PIN_open(&buttonPinState, buttonPinTable); if(!buttonPinHandle) { /* Error initializing button pins */ while(1); } /* Setup callback for button pins */ if (PIN_registerIntCb(buttonPinHandle, &buttonCallbackFxn) != 0) { /* Error registering button callback function */ while(1); } /* Loop forever */ while(1) { sleep(1000); } }
我希望这将有所帮助、
此致、
void buttonCallbackFxn (PIN_Handle handle、PIN_ID pinId){
if (PIN_getInputValue (Rx_intr_pin)== 1){
标志= 1;
}
}
void *mainThread (void *arg0)
{
uint8_t cnt = 0;
uint8_t flag = 0;
buttonPinHandle = PIN_open (&buttonPinState、buttonPinTable);
if (!buttonPinHandle){
/*初始化按钮针脚时出错*/
while (1);
}
/*按钮引脚的设置回调*/
if (PIN_registerIntCb(buttonPinHandle,&buttonCallbackFxn)!= 0){
/*注册按钮回调函数时出错*/
while (1);
}
/*永久循环*/
while (1){
if (flag ==1)
标志= 0;
CNT++;
}
}
使用此格式时,计数不会递增超过1
仅发生一次中断
您好!
我已经审阅了您的代码、有一些地方看起来有点奇怪。
1 -我想问、为什么在 mainThread 中局部声明该标志并且对其外部的访问(在 buttonCallbackFxn 中)。 外观不正确。
2-我想 cnt 和 flag 应该是易失性变量、否则编译器可能会优化 while (1)循环中对 flag 的访问。
3-您能否定义 cnt2并在每次输入 buttonCallbackFxn 时将其递增?
4-您能否确保 while (1)循环不会消耗所有 CPU 时间? 这可以使用信标(而不是"标志")或通过向睡眠状态添加调用来实现。
我希望这将有所帮助、
此致、