问答

汇集网友智慧,解决技术难题

21ic问答首页 - stm32U575 arduino进不了中断

STM32 Arduino 中断

stm32U575 arduino进不了中断

lulugl2022-12-14
最近在学习arduino驱动STM32U575,开发环境为vs code platformio。freertos。我在使用检测IO是可以的,但是用中断,进不了中断。代码如下:#include <Arduino.h>
#include <STM32FreeRTOS.h>
volatile bool btnPressed = true;
volatile bool btnReleased = false;
volatile int couter = 0;

SemaphoreHandle_t xSemaLED = NULL; //创建信号量Handler
volatile TickType_t btnDeounce = 0; //用于button Debounce

TickType_t timeOut = 1000; //用于获取信号量的TimeOut 1000ticks
byte pin = PB7;
void flashLED(void * pt) {

  pinMode(pin,OUTPUT);
  while(1)
  {
    if(xSemaphoreTake(xSemaLED, timeOut) == pdTRUE)
    {
      if((xTaskGetTickCount() - btnDeounce) < 100){
        digitalWrite(pin, !digitalRead(pin));
        vTaskDelay(1000);
      }
    }
  }
}

void buttonPressed()  {
  Serial.println("but clicked.");
  btnDeounce = xTaskGetTickCountFromISR();
  xSemaphoreGiveFromISR(xSemaLED, NULL);
}
void setup() {
  Serial.begin(115200);
  Serial.println("Start flash led....");
  xSemaLED = xSemaphoreCreateBinary();
  if ( xSemaLED == NULL){
    Serial.println("No Enough Ram, Unable to Create Semaphore.");
  }else{
    xTaskCreate(flashLED,
                "Flash LED",
                1024,
                NULL,
                6,
                NULL);
  }
  pinMode(PC13, INPUT_PULLDOWN);
  attachInterrupt(PC13,buttonPressed,HIGH);// 创建外部中断
}

void loop() {
  // put your main code here, to run repeatedly:
}


回答 +关注 15
2506人浏览 0人回答问题 分享 举报
0 个回答

您需要登录后才可以回复 登录 | 注册