您好,我得到了“stm32f10x open107V开发板”,我修改了由制造商给出的PWM代码,但我没有得到任何关于开发板上给出的led的PWM输出,请任何人帮助获取以下代码。
端口B(GPIOB)上的GPIO_引脚0、1、14、15是在开发板上给出的Led引脚。代码是无错误的,并且在链接时没有错误。由于我是乞丐,我不明白是什么问题。

   /**
    -----------------------------------------------------------------*/
          #include "stm32f10x_gpio.h"
          #include "stm32f10x_rcc.h"
          #include "stm32f10x_tim.h"



     TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
     TIM_OCInitTypeDef  TIM_OCInitStructure;
     uint16_t CCR1_Val = 333;
     uint16_t CCR2_Val = 249;
     uint16_t CCR3_Val = 166;
     uint16_t CCR4_Val = 83;
     uint16_t PrescalerValue ;

       /* Private function prototypes -----------------------------------------------*/
    void RCC_Configuration(void);
    void GPIO_Configuration(void);

      /* Private functions ---------------------------------------------------------*/

       /**

     int main(void)
     {

     RCC_Configuration();

    /*GPIO Configuration */
     GPIO_Configuration();


    PrescalerValue =(72000000 / 24000000) - 1;
    /* Time base configuration */
    TIM_TimeBaseStructure.TIM_Period = 665;
    TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue;
    TIM_TimeBaseStructure.TIM_ClockDivision = 4;
    TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

    TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);

    /* PWM1 Mode configuration: Channel1 */
    TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
    TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
    TIM_OCInitStructure.TIM_Pulse = CCR1_Val;
    TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;

    TIM_OC1Init(TIM3, &TIM_OCInitStructure);

    TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Enable);

    /* PWM1 Mode configuration: Channel2 */
    TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
    TIM_OCInitStructure.TIM_Pulse = CCR2_Val;

    TIM_OC2Init(TIM3, &TIM_OCInitStructure);

     TIM_OC2PreloadConfig(TIM3, TIM_OCPreload_Enable);

     /* PWM1 Mode configuration: Channel3 */
     TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
     TIM_OCInitStructure.TIM_Pulse = CCR3_Val;

     TIM_OC3Init(TIM3, &TIM_OCInitStructure);

      TIM_OC3PreloadConfig(TIM3, TIM_OCPreload_Enable);


      /* TIM3 enable counter */
     TIM_Cmd(TIM3, ENABLE);

   while (1)
    {}
   }


   void RCC_Configuration(void)
   {
        /* TIM3 clock enable */
   RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);

    /* GPIOA and GPIOB clock enable */
   RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE);
    }


    void GPIO_Configuration(void)
    {
     GPIO_InitTypeDef GPIO_InitStructure;
      /*GPIOB Configuration: TIM3 channel1, 2, 3 and 4 */
     GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_14|GPIO_Pin_15 ;
     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

     GPIO_Init(GPIOB, &GPIO_InitStructure);

     GPIO_PinRemapConfig(GPIO_FullRemap_TIM3, ENABLE);

     }

最佳答案

首先,如果您查看STM32F107数据表(我假设您有MCU),PB0和PB1管脚可以映射到TIM3_CH3和TIM3_CH4,但是PB14和PB15不能映射到任何TIM3通道——只能映射到TIM1通道请参阅第3节的表5,至少了解我的数据表版本。
其次,在调用GPIO_PinRemapConfig()的情况下,使用AFIO remap功能实际上连接到led的两个管脚(PB0和PB1)不需要重新映射,而其他两个管脚(PB14和PB15)则不需要重新映射到TIM3通道,无论您做什么。
具体来说,只需取消对GPIO_PinRemapConfig()的调用,就可以在两个管脚(PB0和PB1)上获得最小代码更改的PWM输出至于PB14和PB15,您需要配置TIM1,这将需要很多额外的代码不幸的是,你无法将这些引脚映射到TIM3。

07-24 19:29