问答

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

21ic问答首页 - TAG - 2A
  • HC16P122A1/B1 I/O 驱动控制寄存器如何设置

    我在看HC16P122A1/B1的手册的时候看到这两个寄存器,感觉描述得不是很清晰,[img]https://files.oaiusercontent.com/file-ICXi6kDAb2oDoZwv6NZABozs?se=2024-09-06T09%3A28%3A57Z&sp=r&sv=2024-08-04&sr=b&rscc=max-age%3D299%2C%20immutable%2C%20private&rscd=attachment%3B%20filename%3Dimage.png&sig=4Y6vIYt1bRQdcPHI6g/MHtDjWNG0eVojGbr1sAA5Pfc%3D[/img]寄存器DRENxL和DRENxH怎么使用没太理解,比如说我想让某个IO配置成Level1应该怎么配置呢,如果没配置的情况下默认是什么模式呢,还有我在代码里输入这两个寄存器名字编译是未找到的。

    MUC HC 2A I/O 寄存器 驱动控制

    935浏览量 2回复量 关注量
  • GD32A503 TIMER 上溢UP中断与CAP中断优先级有一定几率反转问题

    测试硬件:GD32A503CC测试外设:TIMER0_CH1 测试准备:PE5输入高频PWM 中断优先级配置:UP中断高于CH1中断 void nvic_configuration(void) { nvic_priority_group_set(NVIC_PRIGROUP_PRE1_SUB3); nvic_irq_enable(TIMER0_BRK_UP_TRG_CMT_IRQn, 1, 0); nvic_irq_enable(TIMER0_Channel_IRQn, 1, 1); } 测试定时器配置:配置TIMER0_CH1为双沿输入捕获模式,使能TIMER0 UP上溢与CH1中断。 void timer_configuration(void) { /* TIMER1 configuration: input capture mode ------------------- the external signal is connected to TIMER0 CH1 pin (PE5) the rising edge is used as active edge the TIMER1 CH0CV is used to compute the frequency value ------------------------------------------------------------ */ timer_ic_parameter_struct timer_icinitpara; timer_parameter_struct timer_initpara; rcu_periph_clock_enable(RCU_TIMER0); timer_deinit(TIMER0); /* TIMER0 configuration */ timer_struct_para_init(&timer_initpara); timer_initpara.prescaler = 99; timer_initpara.alignedmode = TIMER_COUNTER_EDGE; timer_initpara.counterdirection = TIMER_COUNTER_UP; timer_initpara.period = 65535; timer_initpara.clockdivision = TIMER_CKDIV_DIV1; timer_initpara.repetitioncounter = 0; timer_init(TIMER0, &timer_initpara); /* TIMER0 configuration */ /* TIMER0 CH1 input capture configuration */ timer_channel_input_struct_para_init(&timer_icinitpara); timer_icinitpara.icpolarity = TIMER_IC_POLARITY_BOTH_EDGE; timer_icinitpara.icselection = TIMER_IC_SELECTION_DIRECTTI; timer_icinitpara.icprescaler = TIMER_IC_PSC_DIV1; timer_icinitpara.icfilter = 0x0; timer_input_capture_config(TIMER0, TIMER_CH_1, &timer_icinitpara); /* auto-reload preload enable */ timer_auto_reload_shadow_enable(TIMER0); /* clear channel 0 interrupt bit */ timer_interrupt_flag_clear(TIMER0, TIMER_INT_FLAG_UP); /* channel 0 interrupt enable */ timer_interrupt_enable(TIMER0, TIMER_INT_UP); /* clear channel 0 interrupt bit */ timer_interrupt_flag_clear(TIMER0, TIMER_INT_FLAG_CH1); /* channel 0 interrupt enable */ timer_interrupt_enable(TIMER0, TIMER_INT_CH1); /* TIMER0 counter enable */ timer_enable(TIMER0); } 中断处理: __IO uint16_t u16_cap_tick = 0; __IO uint32_t u32_cap_tick = 0; __IO uint32_t u32_cap_tick_pre = 0; __IO uint16_t ovf_cont = 0; __IO uint32_t err_cnt = 0; void TIMER0_BRK_UP_TRG_CMT_IRQHandler(void) { if(SET == timer_interrupt_flag_get(TIMER0, TIMER_INT_FLAG_UP)) { /* clear channel1 interrupt bit */ timer_interrupt_flag_clear(TIMER0, TIMER_INT_FLAG_UP); /* count overflow value */ ovf_cont++; } } void TIMER0_Channel_IRQHandler(void) { if(SET == timer_interrupt_flag_get(TIMER0, TIMER_INT_FLAG_CH1)) { /* clear channel1 interrupt bit */ timer_interrupt_flag_clear(TIMER0, TIMER_INT_FLAG_CH1); /* read channel 1 capture value */ u16_cap_tick = timer_channel_capture_value_register_read(TIMER0, TIMER_CH_1); u32_cap_tick_pre = u32_cap_tick; u32_cap_tick = u16_cap_tick + (ovf_cont << 16); if(u32_cap_tick_pre > u32_cap_tick) { err_cnt++; } } } 出现问题:TIMER0 CNT接近上溢时发生CH1捕获中断, 捕获中断有一定几率先于UP中断处理,导致err_cnt计数错误。 示例中,err_cnt会有计数。

    2A 中断优先级 timer ap GD32 MCU

    9539浏览量 11回复量 关注量
  • GD32A503RDT3 ADC+DMA顺序转换问题,没有数据

    void rcu_config(void) { /* enable GPIO clock */ rcu_periph_clock_enable(RCU_GPIOB); rcu_periph_clock_enable(RCU_GPIOE); /* enable ADC0 clock */ rcu_periph_clock_enable(RCU_ADC0); /* enable DMA0 clock */ rcu_periph_clock_enable(RCU_DMA0); } /*! \brief configure the GPIO peripheral \param[in] none \param[out] none \retval none */ void gpio_config(void) { /* config the GPIO as analog mode */ gpio_mode_set(GPIOB, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO_PIN_1);//GPIOB1, gpio_mode_set(GPIOE, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO_PIN_13); } /*! \brief configure the DMA peripheral \param[in] none \param[out] none \retval none */ void dma_config(void) { /* ADC_DMA_channel configuration */ dma_parameter_struct dma_data_parameter; /* ADC DMA_channel configuration */ dma_deinit(DMA0, DMA_CH0); /* initialize DMA single data mode */ dma_data_parameter.periph_addr = (uint32_t)(&ADC_RDATA(ADC0));//外设基地址 dma_data_parameter.periph_inc = DMA_PERIPH_INCREASE_DISABLE;//内存地址增量模式 dma_data_parameter.memory_addr = (uint32_t)adc_value;//数据存放地址 dma_data_parameter.memory_inc = DMA_MEMORY_INCREASE_ENABLE;//内存地址增量模式 dma_data_parameter.periph_width = DMA_PERIPHERAL_WIDTH_16BIT;//dma外设宽度16位,半字 dma_data_parameter.memory_width = DMA_MEMORY_WIDTH_16BIT; dma_data_parameter.direction = DMA_PERIPHERAL_TO_MEMORY;//传输模式,外设到存储(接收) dma_data_parameter.number = 2;//长度 dma_data_parameter.priority = DMA_PRIORITY_HIGH;//优先级高 dma_init(DMA0, DMA_CH0, &dma_data_parameter); dma_circulation_enable(DMA0, DMA_CH0); /* enable DMA channel */ dma_channel_enable(DMA0, DMA_CH0); } /*! \brief configure the ADC peripheral \param[in] none \param[out] none \retval none */ void adc_config(void) { /* config ADC clock */ rcu_adc_clock_config(RCU_CKADC_CKAHB_DIV10); adc_deinit(ADC0); adc_mode_config(ADC_MODE_FREE);//ADC工作在独立模式 /* ADC continous function enable */ adc_special_function_config(ADC0, ADC_SCAN_MODE, ENABLE); adc_special_function_config(ADC0, ADC_CONTINUOUS_MODE, ENABLE); /* ADC trigger config */ adc_external_trigger_source_config(ADC0, ADC_REGULAR_CHANNEL, ADC0_1_EXTTRIG_REGULAR_NONE);//外部触发源设置 /* ADC data alignment config */ adc_data_alignment_config(ADC0, ADC_DATAALIGN_RIGHT);//数据对齐配置 /* ADC channel length config */ adc_channel_length_config(ADC0, ADC_REGULAR_CHANNEL, 2);//用到几个转换通道 /* ADC regular channel config */ adc_regular_channel_config(ADC0, 1, ADC_CHANNEL_7, ADC_SAMPLETIME_55POINT5); adc_regular_channel_config(ADC0, 2, ADC_CHANNEL_9, ADC_SAMPLETIME_55POINT5); adc_external_trigger_config(ADC0, ADC_REGULAR_CHANNEL, ENABLE); /* enable ADC interface */ adc_enable(ADC0); /* ADC DMA function enable */ adc_dma_mode_enable(ADC0); /* ADC calibration and reset calibration */ adc_calibration_enable(ADC0); } main.c /* system clocks configuration */ rcu_config(); /* GPIO configuration */ gpio_config(); /* DMA configuration */ dma_config(); /* ADC configuration */ adc_config(); adc_software_trigger_enable(ADC0, ADC_REGULAR_CHANNEL);

    顺序 2A DMA ADC GD32

    4253浏览量 25回复量 关注量