kopia lustrzana https://github.com/mikaelnousiainen/RS41ng
commit
9fd4446f92
|
@ -4,7 +4,7 @@
|
|||
#include "stm32f10x.h"
|
||||
#include "misc.h"
|
||||
|
||||
uint16_t counts=1666;
|
||||
uint16_t counts=0;
|
||||
|
||||
bool pulse_counter_init()
|
||||
{
|
||||
|
@ -20,43 +20,38 @@ uint16_t pulse_counter_get_counts(){
|
|||
|
||||
void CounterPin_Init(void) {
|
||||
|
||||
//Initialize GPIO typedef
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
//Set pin 11 as input
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
|
||||
//Enable internal pullup
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
|
||||
GPIO_Init(GPIOB, &GPIO_InitStructure);
|
||||
|
||||
|
||||
//Initialize EXTI typedef
|
||||
EXTI_InitTypeDef EXTI_InitStruct;
|
||||
//PB11 is connected to interrupt line 11
|
||||
EXTI_InitStruct.EXTI_Line = EXTI_Line11;
|
||||
//Interrupt mode
|
||||
EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;
|
||||
//Triggers on falling edge
|
||||
EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Falling;
|
||||
//Enable interrupt
|
||||
EXTI_InitStruct.EXTI_LineCmd = ENABLE;
|
||||
//Add to EXTI
|
||||
EXTI_Init(&EXTI_InitStruct);
|
||||
|
||||
//Initialize NVIC typedef
|
||||
NVIC_InitTypeDef NVIC_InitStruct;
|
||||
//PB11 is connected to EXTI_Line11, which has EXTI4_IRQn vector */
|
||||
NVIC_InitStruct.NVIC_IRQChannel = EXTI4_IRQn;
|
||||
//Priority
|
||||
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0x00;
|
||||
//Sub-priority
|
||||
NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0x00;
|
||||
//Enable interrupt
|
||||
NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
|
||||
//Add to NVIC
|
||||
NVIC_Init(&NVIC_InitStruct);
|
||||
//Initialize GPIO typedef
|
||||
GPIO_InitTypeDef gpio_init;
|
||||
//Set pin PB11, with internal pullup, 10MHz speed
|
||||
gpio_init.GPIO_Pin = GPIO_Pin_11;
|
||||
gpio_init.GPIO_Mode = GPIO_Mode_IPU;
|
||||
gpio_init.GPIO_Speed = GPIO_Speed_10MHz;
|
||||
GPIO_Init(GPIOB, &gpio_init);
|
||||
|
||||
//Initialize EXTI typedef
|
||||
EXTI_InitTypeDef exti_init;
|
||||
//PB11 is connected to interrupt line 11, interrupt mode, we trigger on a falling edge and enable it.
|
||||
exti_init.EXTI_Line = EXTI_Line11;
|
||||
exti_init.EXTI_Mode = EXTI_Mode_Interrupt;
|
||||
exti_init.EXTI_Trigger = EXTI_Trigger_Falling;
|
||||
exti_init.EXTI_LineCmd = ENABLE;
|
||||
EXTI_Init(&exti_init);
|
||||
|
||||
//Attach interrupt line to port B
|
||||
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource11);
|
||||
|
||||
//Initialize NVIC typedef
|
||||
NVIC_InitTypeDef NVIC_InitStruct;
|
||||
//PB11 is connected to EXTI_Line11, which has EXTI15_10_IRQn vector, we leave 00 priority for now.
|
||||
NVIC_InitStruct.NVIC_IRQChannel = EXTI15_10_IRQn;
|
||||
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0x00;
|
||||
NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0x00;
|
||||
NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&NVIC_InitStruct);
|
||||
}
|
||||
|
||||
void EXTI4_IRQHandler(void){
|
||||
void EXTI15_10_IRQHandler(void){
|
||||
counts = counts+1;
|
||||
EXTI_ClearITPendingBit(EXTI_Line11); //Clear the interrupt flag bit on LINE11
|
||||
}
|
Ładowanie…
Reference in New Issue