Edge trigger works
This commit is contained in:
+39
-4
@@ -66,11 +66,7 @@ int _write(int file, char *ptr, int len) {
|
||||
|
||||
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
||||
{
|
||||
uint32_t current_count = EXT_TIMER.Instance->CNT;
|
||||
uint32_t difference = current_count-last_count;
|
||||
|
||||
last_count = current_count;
|
||||
printf("%d\n", difference);
|
||||
}
|
||||
|
||||
void USB_CDC_RxHandler(uint8_t* Buf, uint32_t Len)
|
||||
@@ -85,6 +81,34 @@ void USB_CDC_RxHandler(uint8_t* Buf, uint32_t Len)
|
||||
|
||||
}
|
||||
|
||||
uint32_t check_pin_state()
|
||||
{
|
||||
return HAL_GPIO_ReadPin(PIN_GPIO_Port, PIN_Pin);
|
||||
}
|
||||
|
||||
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
|
||||
{
|
||||
uint32_t current_count = EXT_TIMER.Instance->CNT;
|
||||
|
||||
if (check_pin_state() )
|
||||
{
|
||||
// printf("RISING\n");
|
||||
//Reset
|
||||
last_count = current_count;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// printf("FALLING\n");
|
||||
//Send
|
||||
uint32_t difference = current_count-last_count;
|
||||
|
||||
|
||||
printf("%d\n", difference);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void receive_handler();
|
||||
/* USER CODE END PFP */
|
||||
|
||||
@@ -295,6 +319,7 @@ static void MX_TIM2_Init(void)
|
||||
*/
|
||||
static void MX_GPIO_Init(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
||||
/* USER CODE END MX_GPIO_Init_1 */
|
||||
|
||||
@@ -302,6 +327,16 @@ static void MX_GPIO_Init(void)
|
||||
__HAL_RCC_GPIOF_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
|
||||
/*Configure GPIO pin : PIN_Pin */
|
||||
GPIO_InitStruct.Pin = PIN_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
HAL_GPIO_Init(PIN_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/* EXTI interrupt init*/
|
||||
HAL_NVIC_SetPriority(EXTI1_IRQn, 0, 0);
|
||||
HAL_NVIC_EnableIRQ(EXTI1_IRQn);
|
||||
|
||||
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
||||
/* USER CODE END MX_GPIO_Init_2 */
|
||||
}
|
||||
|
||||
@@ -199,6 +199,20 @@ void SysTick_Handler(void)
|
||||
/* please refer to the startup file (startup_stm32g4xx.s). */
|
||||
/******************************************************************************/
|
||||
|
||||
/**
|
||||
* @brief This function handles EXTI line1 interrupt.
|
||||
*/
|
||||
void EXTI1_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN EXTI1_IRQn 0 */
|
||||
|
||||
/* USER CODE END EXTI1_IRQn 0 */
|
||||
HAL_GPIO_EXTI_IRQHandler(PIN_Pin);
|
||||
/* USER CODE BEGIN EXTI1_IRQn 1 */
|
||||
|
||||
/* USER CODE END EXTI1_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles USB low priority interrupt remap.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user