Exemplo n.º 1
0
void Config()
{
  //System clock at power up is HSI/8 = 16MHz/8 = 2MHz
  //CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_1);  //set HSI/4 = 4MHz SysClk to Core and Memory, minimum clock = 125KHz for CLK_SYSCLKDiv_128
  //PWR_PVDCmd(ENABLE);  //Power voltage detector and brownout Reset unit supply current 2,6uA
  //PWR_PVDLevelConfig(PWR_PVDLevel_2V26); //set Programmable voltage detector threshold to 2,26V
  //PWR_GetFlagStatus(PWR_FLAG_PVDOF);  //checks whether the specified PWR flag is set or not
  
  //Configure external interrupts - BTN1 and BTN2 presses
  EXTI_SetPinSensitivity(EXTI_Pin_0, EXTI_Trigger_Falling_Low);
  //EXTI_SetPinSensitivity(EXTI_Pin_4, EXTI_Trigger_Falling_Low);
  //EXTI_SelectPort(EXTI_Port_B);
  //EXTI_SetHalfPortSelection(EXTI_HalfPort_B_MSB, ENABLE);

  /* Input FL IT - onboard Button, external pull-up */
  GPIO_Init(BTN1_PORT, BTN1_PIN, GPIO_Mode_In_FL_IT);
  GPIO_Init(BTN2_PORT, BTN2_PIN, GPIO_Mode_In_FL_IT);

  // Timer 3 Configuration
  CLK_PeripheralClockConfig(CLK_Peripheral_TIM3, ENABLE);
  TIM3_TimeBaseInit(TIM3_Prescaler_2, TIM3_CounterMode_Up, 700); // 1MHz timer clock
  TIM3_OC1Init(TIM3_OCMode_PWM1,
               TIM3_OutputState_Enable,
               350,
               TIM3_OCPolarity_Low,
               TIM3_OCIdleState_Reset);
  TIM3_ARRPreloadConfig(ENABLE);
  TIM3_OC1PreloadConfig(ENABLE);
  TIM3_CtrlPWMOutputs(ENABLE);
  TIM3_Cmd(DISABLE);
  
  /* RFM85W pins */
  GPIO_Init(RFM_DATA_PORT, RFM_DATA_PIN, GPIO_Mode_Out_PP_Low_Fast);
  GPIO_Init(RFM_ON_PORT,   RFM_ON_PIN,   GPIO_Mode_Out_PP_Low_Fast);
  
  /* Output PP High - bicolor LED to GND */
  GPIO_Init(LED_PORT, LED_PIN1, GPIO_Mode_Out_PP_Low_Slow);
  GPIO_Init(LED_PORT, LED_PIN2, GPIO_Mode_Out_PP_Low_Slow);

  RFM_OFF;
  //RFM_DATA(0);
}
Exemplo n.º 2
0
/**
  * @brief  Configure TIM1,2,3 peripherals 
  * @param  None
  * @retval None
  */
static void TIM_Config(void)
{
  /* TIM1 configuration:
   - TIM1CLK is set to 2 MHz, the TIM2 Prescaler is equal to 15 so the TIM1 counter
   clock used is 2 MHz / (15 + 1) = 125 000 Hz
   - TIM1 Channel 1 output frequency = TIM1CLK / (TIM1_PERIOD + 1) * (TIM1_PRESCALER + 1)
                                    = 2 000 000 / 256 * 16 = 488.28 Hz */
  /* Time Base configuration */
  TIM1_TimeBaseInit(TIM1_PRESCALER, TIM1_CounterMode_Up, TIM1_PERIOD, TIM1_REPETITION_COUNTER);

  /* TIM1 Channel 1 Configuration in PWM2 mode */
  TIM1_OC1Init(TIM1_OCMode_PWM2, TIM1_OutputState_Enable, TIM1_OutputNState_Disable, TIM1_CCR1_VAL,
               TIM1_OCPolarity_Low, TIM1_OCNPolarity_Low, TIM1_OCIdleState_Set, TIM1_OCNIdleState_Set);

  /* Master Mode selection: Update event */
  TIM1_SelectOutputTrigger(TIM1_TRGOSource_Update);

  /* TIM2 configuration:
   - TIM2 is connected to TIM1 Update so TIM2CLK is equal to 
     TIM1 output clock / (TIM1_REPETITION_COUNTER + 1) = 488.28 / 5 = 97.65 Hz
    - TIM2 Prescaler is equal to 1 so the TIM2 counter clock used is 97.65 / 1 = 97.65 Hz
    - TIM2 Channel 1 output frequency = TIM2CLK / (TIM2_PERIOD + 1) * TIM2_Prescaler
                                     = 97.65 / 3 * 1 = 32.55 Hz */
  /* Time Base configuration */
  TIM2_TimeBaseInit(TIM2_Prescaler_1, TIM2_CounterMode_Up, TIM2_PERIOD);

  TIM2_OC1Init(TIM2_OCMode_PWM2, TIM2_OutputState_Enable, TIM2_CCR1_VAL,
               TIM2_OCPolarity_Low, TIM2_OCIdleState_Reset);

  /* TIM2 Slave Mode selection: Gated mode */
  TIM2_SelectSlaveMode(TIM2_SlaveMode_Gated);
  TIM2_SelectInputTrigger(TIM2_TRGSelection_TIM1);

  /* TIM3 configuration:
   - TIM3 is connected to TIM1 Update so TIM3CLK is equal to 
     TIM1 output clock / (TIM1_REPETITION_COUNTER + 1) = 488.28 / 5 = 97.65 Hz
    - TIM3 Prescaler is equal to 1 so the TIM3 counter clock used is 97.65 / 1 = 97.65 Hz
    - TIM3 Channel 1 output frequency = TIM3CLK / (TIM3_PERIOD + 1) * TIM3Prescaler
                                     = 97.65 / 4 * 1 = 24.41 Hz */
  /* Time Base configuration */
  TIM3_TimeBaseInit(TIM3_Prescaler_1, TIM3_CounterMode_Up, TIM3_PERIOD);

  TIM3_OC1Init(TIM3_OCMode_PWM2, TIM3_OutputState_Enable, TIM3_CCR1_VAL,
               TIM3_OCPolarity_Low, TIM3_OCIdleState_Reset);

  /* TIM3 Slave Mode selection: Gated mode */
  TIM3_SelectSlaveMode(TIM3_SlaveMode_Gated);
  TIM3_SelectInputTrigger(TIM3_TRGSelection_TIM1);

  /* Main Output Enable */
  TIM1_CtrlPWMOutputs(ENABLE);
  TIM2_CtrlPWMOutputs(ENABLE);
  TIM3_CtrlPWMOutputs(ENABLE);

  /* TIM2 counter enable */
  TIM2_Cmd(ENABLE);
  /* TIM3 counter enable */
  TIM3_Cmd(ENABLE);
  /* TIM1 counter enable */
  TIM1_Cmd(ENABLE);
}