into exti IRQ OK
This commit is contained in:
parent
8abd25d7fa
commit
d51a97df32
@ -35,4 +35,8 @@ void ultrasonic_config(void);
|
|||||||
void ultrasonic_peripheral_config(void);
|
void ultrasonic_peripheral_config(void);
|
||||||
void ultrasonic_pwm_out_cycles(uint8_t cycles);
|
void ultrasonic_pwm_out_cycles(uint8_t cycles);
|
||||||
|
|
||||||
|
|
||||||
|
void timer15_config(void);
|
||||||
|
void recevice_exti_config(void);
|
||||||
|
|
||||||
#endif //ULTRASONIC_DRIVER_H
|
#endif //ULTRASONIC_DRIVER_H
|
||||||
|
@ -115,4 +115,30 @@ void TIMER13_IRQHandler(void) {
|
|||||||
}
|
}
|
||||||
led_status = !led_status;
|
led_status = !led_status;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TIMER15_IRQHandler(void) {
|
||||||
|
if (timer_interrupt_flag_get(TIMER15, TIMER_INT_FLAG_UP) == SET)
|
||||||
|
{
|
||||||
|
timer_interrupt_flag_clear(TIMER15, TIMER_INT_FLAG_UP);
|
||||||
|
|
||||||
|
exti_interrupt_enable(EXTI_0);
|
||||||
|
// timer_enable(TIMER14);
|
||||||
|
|
||||||
|
gpio_bit_toggle(GPIOA, GPIO_PIN_7);
|
||||||
|
|
||||||
|
timer_disable(TIMER15);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EXTI0_1_IRQHandler(void) {
|
||||||
|
if (exti_interrupt_flag_get(EXTI_0) == SET) {
|
||||||
|
exti_interrupt_flag_clear(EXTI_0);
|
||||||
|
|
||||||
|
gpio_bit_toggle(GPIOA, GPIO_PIN_5);
|
||||||
|
|
||||||
|
timer_event_software_generate(TIMER14, TIMER_EVENT_SRC_CH0G);
|
||||||
|
|
||||||
|
exti_interrupt_disable(EXTI_0);
|
||||||
|
}
|
||||||
}
|
}
|
@ -26,11 +26,12 @@ int main(void)
|
|||||||
systick_config();
|
systick_config();
|
||||||
/* configure ultrasonic board hardware */
|
/* configure ultrasonic board hardware */
|
||||||
ultrasonic_peripheral_config();
|
ultrasonic_peripheral_config();
|
||||||
|
timer15_config();
|
||||||
|
|
||||||
|
|
||||||
/* ---------- debug start ---------- */
|
/* ---------- debug start ---------- */
|
||||||
|
|
||||||
|
recevice_exti_config();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ void led_config(void)
|
|||||||
|
|
||||||
timer_auto_reload_shadow_enable(LED_TIMER);
|
timer_auto_reload_shadow_enable(LED_TIMER);
|
||||||
timer_interrupt_enable(LED_TIMER, TIMER_INT_UP);
|
timer_interrupt_enable(LED_TIMER, TIMER_INT_UP);
|
||||||
nvic_irq_enable(LED_IRQ, 0);
|
nvic_irq_enable(LED_IRQ, 3);
|
||||||
timer_enable(LED_TIMER);
|
timer_enable(LED_TIMER);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,6 +107,8 @@ void ultrasonic_pwm_out_cycles(uint8_t cycles) {
|
|||||||
timer_channel_output_mode_config(US_TRAN_TIMER, US_TRAN_CH, TIMER_OC_MODE_PWM1);
|
timer_channel_output_mode_config(US_TRAN_TIMER, US_TRAN_CH, TIMER_OC_MODE_PWM1);
|
||||||
timer_enable(US_TRAN_TIMER);
|
timer_enable(US_TRAN_TIMER);
|
||||||
|
|
||||||
|
timer_enable(TIMER15);
|
||||||
|
|
||||||
while (current_cycle < cycles)
|
while (current_cycle < cycles)
|
||||||
{
|
{
|
||||||
while (!timer_interrupt_flag_get(US_TRAN_TIMER, TIMER_INT_FLAG_UP));
|
while (!timer_interrupt_flag_get(US_TRAN_TIMER, TIMER_INT_FLAG_UP));
|
||||||
@ -120,3 +122,48 @@ void ultrasonic_pwm_out_cycles(uint8_t cycles) {
|
|||||||
// gpio_bit_reset(GPIOB, GPIO_PIN_1);
|
// gpio_bit_reset(GPIOB, GPIO_PIN_1);
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void timer15_config(void) {
|
||||||
|
rcu_periph_clock_enable(RCU_GPIOA);
|
||||||
|
|
||||||
|
gpio_mode_set(GPIOA, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO_PIN_7);
|
||||||
|
gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_7);
|
||||||
|
gpio_bit_write(GPIOA, GPIO_PIN_7, SET);
|
||||||
|
|
||||||
|
rcu_periph_clock_enable(RCU_TIMER15);
|
||||||
|
timer_deinit(TIMER15);
|
||||||
|
|
||||||
|
timer_parameter_struct timer_initpara;
|
||||||
|
timer_struct_para_init(&timer_initpara);
|
||||||
|
timer_initpara.prescaler =71;
|
||||||
|
timer_initpara.alignedmode =TIMER_COUNTER_EDGE;
|
||||||
|
timer_initpara.counterdirection =TIMER_COUNTER_UP;
|
||||||
|
timer_initpara.period =230 - 1;
|
||||||
|
timer_initpara.clockdivision =TIMER_CKDIV_DIV1;
|
||||||
|
timer_initpara.repetitioncounter =0;
|
||||||
|
timer_init(TIMER15, &timer_initpara);
|
||||||
|
|
||||||
|
timer_auto_reload_shadow_enable(TIMER15); //使能自动影子重载
|
||||||
|
timer_interrupt_enable(TIMER15, TIMER_INT_UP); // 使能自动重载中断
|
||||||
|
nvic_irq_enable(TIMER15_IRQn, 2U);
|
||||||
|
}
|
||||||
|
|
||||||
|
void recevice_exti_config(void) {
|
||||||
|
rcu_periph_clock_enable(RCU_GPIOA);
|
||||||
|
rcu_periph_clock_enable(RCU_CFGCMP);
|
||||||
|
|
||||||
|
gpio_mode_set(GPIOA, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO_PIN_5);
|
||||||
|
gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_5);
|
||||||
|
gpio_bit_write(GPIOA, GPIO_PIN_5, SET);
|
||||||
|
|
||||||
|
exti_deinit();
|
||||||
|
|
||||||
|
gpio_mode_set(GPIOA, GPIO_MODE_INPUT, GPIO_PUPD_NONE, GPIO_PIN_0);
|
||||||
|
nvic_irq_enable(EXTI0_1_IRQn, 1U);
|
||||||
|
syscfg_exti_line_config(EXTI_SOURCE_GPIOA, EXTI_SOURCE_PIN0);
|
||||||
|
|
||||||
|
exti_init(EXTI_0, EXTI_INTERRUPT, EXTI_TRIG_FALLING);
|
||||||
|
exti_flag_clear(EXTI_0);
|
||||||
|
|
||||||
|
exti_interrupt_enable(EXTI_0);
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user