问答

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

Ericknfk

TA的家园币:32  

  • 为什么STM32在使用定时器中断的时候ARR的参数不能给0?

    我在使用ETR外部时钟信号时,想实现类似于外部中断的,信号来一次进入一次中断的操作。但是发现当TIM_Period参数给1-1,也就是0时,无法正常进入中断。但是将参数调整为2-1时,来两次信号又可以进入中断,请问这是为什么?uint16_tCount;voidTIM_QuicklyInit(void);intmain(void){TIM_QuicklyInit();OLED_Init();OLED_ShowString(1,1,"Counts:");while(1){OLED_ShowNum(2,1,Count,4);OLED_ShowNum(3,1,TIM_GetCounter(TIM2),1);}}voidTIM_QuicklyInit(void){RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE);RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);GPIO_InitTypeDefGPIOInitstructure;GPIOInitstructure.GPIO_Mode=GPIO_Mode_IPD;GPIOInitstructure.GPIO_Pin=GPIO_Pin_0;GPIOInitstructure.GPIO_Speed=GPIO_Speed_50MHz;GPIO_Init(GPIOA,&GPIOInitstructure);TIM_ETRClockMode2Config(TIM2,TIM_ExtTRGPSC_OFF,TIM_ExtTRGPolarity_Inverted,0x0F);TIM_TimeBaseInitTypeDefTimeInitstructure;TimeInitstructure.TIM_CounterMode=TIM_CounterMode_Up;TimeInitstructure.TIM_ClockDivision=TIM_CKD_DIV4;TimeInitstructure.TIM_Period=1-1;TimeInitstructure.TIM_Prescaler=1-1;TimeInitstructure.TIM_RepetitionCounter=0;TIM_TimeBaseInit(TIM2,&TimeInitstructure);TIM_ClearFlag(TIM2,TIM_FLAG_Update);TIM_Cmd(TIM2,ENABLE);TIM_ITConfig(TIM2,TIM_IT_Update,ENABLE);NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);NVIC_InitTypeDefNVICInitstructure;NVICInitstructure.NVIC_IRQChannel=TIM2_IRQn;NVICInitstructure.NVIC_IRQChannelCmd=ENABLE;NVICInitstructure.NVIC_IRQChannelPreemptionPriority=2;NVICInitstructure.NVIC_IRQChannelSubPriority=2;NVIC_Init(&NVICInitstructure);}voidTIM2_IRQHandler(void){if(TIM_GetFlagStatus(TIM2,TIM_IT_Update)==SET)Count++;TIM_ClearFlag(TIM2,TI

    单片机 嵌入式 ST

    2023-09-04 8
  • STM32的DMA中传输数据宽度与实际宽度不符会怎样?

    如果uint16_tA[]={0,1,2,3},B[]={0,0,0,0};要将A数组的数据用DMA传递到B数组中,但是在设置数据宽度的时候设置的是一位DMA_Initstructure.DMA_MemoryDataSize=DMA_MemoryDataSize_Byte。将结果显示在OLED屏幕上,结果只有前两个数正确的传到了B数组中,B数组在OLDE上显示的是0,1,0,0。出现这种问题的根本原因是什么。

    ST 嵌入式

    2023-08-21 21