|
进入中断后,自加,竟然会出错??
static volatile uint32_t pos_flow = 1;
static volatile uint32_t neg_flow = 1;
/**
* @brief This function handles External lines interrupt request.
*/
void EXTI4_15_IRQHandler(void) {
// gpio_exti_callback();
// static volatile uint32_t pos_flow = 1;
// static volatile uint32_t neg_flow = 1;
static uint32_t k = 0x22;
static uint8_t new = 0, last = 0;
uint8_t flag = 0;
// DISABLE_INT();
/* C线 */
if (__HAL_GPIO_EXTI_GET_IT(GPIO_PIN_4) != RESET) {
hall_info.storage[hall_info.count++] |= EXTI_A;
// hall_info.reg |= EXTI_A;
new = EXTI_A;
flag = 1;
__HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_4);
}
/* B线 */
if (__HAL_GPIO_EXTI_GET_IT(GPIO_PIN_5) != RESET) {
hall_info.storage[hall_info.count++] |= EXTI_B;
// hall_info.reg |= EXTI_B;
new = EXTI_B;
flag = 1;
__HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_5);
}
/* A线 */
if (__HAL_GPIO_EXTI_GET_IT(GPIO_PIN_6) != RESET) {
hall_info.storage[hall_info.count++] |= EXTI_C;
// hall_info.reg |= EXTI_C;
new = EXTI_C;
flag = 1;
__HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_6);
}
if (flag) {
if (last == 0) {
last = new;
} else {
switch (new) {
case EXTI_C:/* C */
/* 正转 */
if (last == EXTI_A) {
pos_flow++;
}
/* 反转 */
if (last == EXTI_B) {
neg_flow++;
}
break;
case EXTI_B:/* B */
/* 正转 */
if (last == EXTI_C) {
pos_flow++;
}
/* 反转 */
if (last == EXTI_A) {
neg_flow++;
}
break;
case EXTI_A:/* A */
/* 正转 */
if (last == EXTI_B) {
pos_flow++;
}
/* 反转 */
if (last == EXTI_C) {
neg_flow++;
}
break;
default:
/* 错误 */
hall_info.error += 1; /* 读取后才可以修改 */
break;
}
last = new;
}
// hall_info.neg_flow = neg_flow;
// hall_info.pos_flow = pos_flow;
// __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
printf("neg_flow:%u\r\n", neg_flow);
printf("pos_flow:%u\r\n", pos_flow);
printf("k:%u\r\n", k++);
}
// ENABLE_INT();
}
|
|