Testprogramm für Hardwaretimer TIM2 und TIM3 mit Nucleo-F401RE

Dependencies:   mbed-os

Revision:
3:b0716d14c3bf
Parent:
2:a5ee88ab46b2
--- a/main.cpp	Thu Nov 12 13:28:29 2020 +0000
+++ b/main.cpp	Thu Oct 14 10:10:33 2021 +0000
@@ -10,62 +10,69 @@
     PC2=!PC2;
 }
 
-void TIM6_IRQHandler(void)
+void TIM2_IRQHandler(void)
 {
     myled=!myled;
-    TIM6->SR=0;
-    HAL_NVIC_ClearPendingIRQ(TIM6_IRQn);
+    TIM2->SR=0;
+    HAL_NVIC_ClearPendingIRQ(TIM2_IRQn);
 }
-void TIM7_IRQHandler(void)
+void TIM3_IRQHandler(void)
 {
     myled2=!myled2;
-    TIM7->SR=0;
-    HAL_NVIC_ClearPendingIRQ(TIM7_IRQn);
+    TIM3->SR=0;
+    HAL_NVIC_ClearPendingIRQ(TIM3_IRQn);
 }
 InterruptIn PA1(PA_1);
+void EX1init(void);
+
+
+void NVIC_Init(void)
+{
+    /* TIM2_IRQn interrupt configuration */
+    NVIC_SetVector(TIM2_IRQn, (uint32_t)&TIM2_IRQHandler);
+    HAL_NVIC_EnableIRQ(TIM2_IRQn);
+   /* TIM3_IRQn interrupt configuration */
+    NVIC_SetVector(TIM3_IRQn, (uint32_t)&TIM3_IRQHandler);
+    HAL_NVIC_EnableIRQ(TIM3_IRQn);
+}
+
+/* TIM2 init function */
+void TIM2_Init(void)
+{
+    RCC->APB1ENR|=0b00001;  //Clock Enable
+    TIM2->PSC=3199;         //Prescaler 100µs
+    TIM2->ARR=5000;         //Autoreload 5000*100µs = 0,5s
+    TIM2->DIER=1;           //UIE = 1 (Update Interrupt Enable)
+    TIM2->SR=0;             //UIF =0 (Update Interrupt Flag)
+    TIM2->CR1=1;            //CEN=1 (Counter Enable)
+}
+void TIM3_Init(void);
+
+
+
+int main()
+{
+    TIM2_Init();
+    TIM3_Init();
+    EX1init();
+    NVIC_Init();
+    while(1) {
+    }
+
+}
+
 void EX1init(void)
 {
 PA1.rise(&EX1IRQhandler);
 PA1.mode(PullDown);
 }
 
-void NVIC_Init(void)
-{
-    /* TIM6_IRQn interrupt configuration */
-    NVIC_SetVector(TIM6_IRQn, (uint32_t)&TIM6_IRQHandler);
-    HAL_NVIC_EnableIRQ(TIM6_IRQn);
-   /* TIM7_IRQn interrupt configuration */
-    NVIC_SetVector(TIM7_IRQn, (uint32_t)&TIM7_IRQHandler);
-    HAL_NVIC_EnableIRQ(TIM7_IRQn);
-}
-
-/* TIM6 init function */
-void TIM6_Init(void)
+void TIM3_Init(void)
 {
-    RCC->APB1ENR|=0b10000;  //Clock Enable
-    TIM6->PSC=3199;         //Prescaler 100µs
-    TIM6->ARR=5000;         //Autoreload 5000*100µs = 0,5s
-    TIM6->DIER=1;           //UIE = 1 (Update Interrupt Enable)
-    TIM6->SR=0;             //UIF =0 (Update Interrupt Flag)
-    TIM6->CR1=1;            //CEN=1 (Counter Enable)
-}
-void TIM7_Init(void)
-{
-    RCC->APB1ENR|=0b100000;  //Clock Enable
-    TIM7->PSC=3199;         //Prescaler 100µs
-    TIM7->ARR=15000;         //Autoreload 15000*100µs = 1,5s
-    TIM7->DIER=1;           //UIE = 1 (Update Interrupt Enable)
-    TIM7->SR=0;             //UIF =0 (Update Interrupt Flag)
-    TIM7->CR1=1;            //CEN=1 (Counter Enable)
-}
-
-int main()
-{
-    TIM6_Init();
-    TIM7_Init();
-    EX1init();
-    NVIC_Init();
-    while(1) {
-    }
-
+    RCC->APB1ENR|=0b000010;  //Clock Enable
+    TIM3->PSC=3199;         //Prescaler 100µs
+    TIM3->ARR=15000;         //Autoreload 15000*100µs = 1,5s
+    TIM3->DIER=1;           //UIE = 1 (Update Interrupt Enable)
+    TIM3->SR=0;             //UIF =0 (Update Interrupt Flag)
+    TIM3->CR1=1;            //CEN=1 (Counter Enable)
 }
\ No newline at end of file