Esempio n. 1
0
/**
  * @brief  Configures the different system clocks.
  * @param  None
  * @retval None
  */
void RCC_Configuration(void)
{    
    /* DMA clock enable */
    RCC_AHBPeriphClock_Enable(RCC_AHBPERIPH_DMA1, ENABLE);

    /* Enable GPIO clock */
    RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_GPIOA , ENABLE);

    /* Enable USART1 Clock */
    RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_USART1, ENABLE); 

    /* Enable USART2 Clock */
    RCC_APB1PeriphClock_Enable(RCC_APB1PERIPH_USART2, ENABLE);
}
Esempio n. 2
0
/**
  * @brief  Configure the TIMER peripheral.
  * @param  None
  * @retval None
  */
void TIMER_Configuration(void)
{
    /* ---------------------------------------------------------------------------
    TIMER2 Configuration: Output Compare Toggle Mode:
    TIMER2CLK = SystemCoreClock / 36000=2K,
    CH2 update rate = TIMER2 counter clock / CHCC2 = 2000/4000 = 0.5 Hz
    ----------------------------------------------------------------------------*/
    TIMER_BaseInitPara TIMER_TimeBaseStructure;
    TIMER_OCInitPara  TIMER_OCInitStructure;

    /* TIMERS clock enable */
    RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_TIMER1|RCC_APB2PERIPH_TIMER15|RCC_APB2PERIPH_TIMER16|RCC_APB2PERIPH_TIMER17,ENABLE);
    RCC_APB1PeriphClock_Enable(RCC_APB1PERIPH_TIMER2|RCC_APB1PERIPH_TIMER3|RCC_APB1PERIPH_TIMER6|RCC_APB1PERIPH_TIMER14,ENABLE);

    /* TIMER2  configuration */
    TIMER_DeInit(TIMER2);
    TIMER_TimeBaseStructure.TIMER_Prescaler     = 35999;
    TIMER_TimeBaseStructure.TIMER_CounterMode   = TIMER_COUNTER_UP;
    TIMER_TimeBaseStructure.TIMER_Period        = 3999;
    TIMER_TimeBaseStructure.TIMER_ClockDivision = TIMER_CDIV_DIV1;
    TIMER_BaseInit(TIMER2,&TIMER_TimeBaseStructure);

    /* CH2 Configuration in OC_TOGGLE mode */
    TIMER_OCInitStructure.TIMER_OCMode      = TIMER_OC_MODE_TOGGLE;
    TIMER_OCInitStructure.TIMER_OCPolarity  = TIMER_OC_POLARITY_HIGH;
    TIMER_OCInitStructure.TIMER_OutputState = TIMER_OUTPUT_STATE_ENABLE;
    TIMER_OCInitStructure.TIMER_Pulse       = 3999;
    TIMER_OC2_Init(TIMER2, &TIMER_OCInitStructure);
    TIMER_OC2_Preload(TIMER2,TIMER_OC_PRELOAD_DISABLE);

    /* Auto-reload preload enable */
    TIMER_CARLPreloadConfig(TIMER2,ENABLE);
    /* TIMER enable counter*/
    TIMER_Enable( TIMER2, ENABLE );
}
Esempio n. 3
0
/**
  * @brief  RCC configuration.
  * @param  None
  * @retval None
  */
void RCC_Configuration(void)
{
    RCC_AHBPeriphClock_Enable(RCC_AHBPERIPH_GPIOA,ENABLE);
    RCC_AHBPeriphClock_Enable(RCC_AHBPERIPH_GPIOB,ENABLE);
    RCC_AHBPeriphClock_Enable(RCC_AHBPERIPH_GPIOC,ENABLE);
    RCC_APB1PeriphClock_Enable(RCC_APB1PERIPH_TIMER2,ENABLE);
    RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_CMP ,ENABLE);
}
Esempio n. 4
0
/**
  * @brief  Configure system clocks.
  * @param  None
  * @retval None
  */
void RCC_Configuration(void)
{
    /* ADCCLK = PCLK2/6 */
    RCC_ADCCLKConfig(RCC_ADCCLK_APB2_DIV6);
    /* Enable GPIO clock */
    RCC_AHBPeriphClock_Enable(RCC_AHBPERIPH_GPIOC|RCC_AHBPERIPH_GPIOA, ENABLE);
    /* Enable ADC clock */
    RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_ADC1, ENABLE);
}
Esempio n. 5
0
/**
  * @brief  Configure the GPIO ports.
  * @param  None
  * @retval None
  */
void LED_config(void)
{    
    GPIO_InitPara GPIO_InitStructure;

    RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_GPIOC,ENABLE);

    GPIO_InitStructure.GPIO_Pin   = GPIO_PIN_0;
    GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_50MHZ;
    GPIO_InitStructure.GPIO_Mode  = GPIO_MODE_OUT_PP;

    GPIO_Init(GPIOC,&GPIO_InitStructure);
}
Esempio n. 6
0
/**
  * @brief  Configure system clocks.
  * @param  None
  * @retval None
  */
void RCC_Configuration(void)
{
    /* Configure the ADCCLK to 12MHz */
    RCC_ADCCLKConfig(RCC_ADCCLK_APB2_DIV6);
    
    /* Enable DMA1 and GPIO clock */
    RCC_AHBPeriphClock_Enable(RCC_AHBPERIPH_DMA1|RCC_AHBPERIPH_GPIOA | RCC_AHBPERIPH_GPIOC , ENABLE);
    
    /* Enable ADC and TIM2 clock */
    RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_ADC1, ENABLE);
    RCC_APB1PeriphClock_Enable(RCC_APB1PERIPH_TIMER2, ENABLE);
}
Esempio n. 7
0
/**
  * @brief  Configures the different GPIO ports.
  * @param  None
  * @retval None
  */
void GPIO_Configuration(void)
{
    GPIO_InitPara GPIO_InitStructure;

    RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_GPIOA ,ENABLE);
    /* Once the DAC channel is enabled, the corresponding GPIO pin is automatically
    connected to the DAC converter. In order to avoid parasitic consumption,
    the GPIO pin should be configured in analog */
    GPIO_InitStructure.GPIO_Pin =  GPIO_PIN_4 | GPIO_PIN_5;
    GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AIN;
    GPIO_Init(GPIOA, &GPIO_InitStructure);
}
Esempio n. 8
0
void adc_init(void)
{	  
    DMA_InitPara DMA_InitStructure;
    ADC_InitPara ADC_InitStructure;
    
    RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_ADC1, ENABLE);	  

    RCC_ADCCLKConfig(RCC_ADCCLK_APB2_DIV6);

    RCC_AHBPeriphClock_Enable(RCC_AHBPERIPH_DMA1, ENABLE);		     

    DMA_InitStructure.DMA_PeripheralBaseAddr = 0x4001244C; 
    DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)adcarray; 
    DMA_InitStructure.DMA_DIR = DMA_DIR_PERIPHERALSRC;  
    DMA_InitStructure.DMA_BufferSize = 4;	
    DMA_InitStructure.DMA_PeripheralInc = DMA_PERIPHERALINC_DISABLE;	
    DMA_InitStructure.DMA_MemoryInc = DMA_MEMORYINC_ENABLE;	
    DMA_InitStructure.DMA_PeripheralDataSize = DMA_PERIPHERALDATASIZE_HALFWORD; 
    DMA_InitStructure.DMA_MemoryDataSize = DMA_MEMORYDATASIZE_HALFWORD; 
    DMA_InitStructure.DMA_Mode = DMA_MODE_CIRCULAR; 
    DMA_InitStructure.DMA_Priority = DMA_PRIORITY_HIGH;
    DMA_InitStructure.DMA_MTOM = DMA_MEMTOMEM_DISABLE; 
		
    DMA_Init(DMA1_CHANNEL1, &DMA_InitStructure);	 
  
    DMA_Enable(DMA1_CHANNEL1, ENABLE);  
    
  //  ADC_DeInit(&ADC_InitStructure);
		
    ADC_InitStructure.ADC_Mode_Scan = ENABLE;		 
    ADC_InitStructure.ADC_Mode_Continuous = ENABLE;  
    ADC_InitStructure.ADC_Trig_External = ADC_EXTERNAL_TRIGGER_MODE_NONE;  
    ADC_InitStructure.ADC_Data_Align = ADC_DATAALIGN_RIGHT;	
    ADC_InitStructure.ADC_Channel_Number = 4;  
		
    ADC_Init(&ADC_InitStructure);  
    // current?
    ADC_RegularChannel_Config(ADC_CHANNEL_7, 1, ADC_SAMPLETIME_239POINT5);
		// battery channel
    ADC_RegularChannel_Config(ADC_CHANNEL_5, 2, ADC_SAMPLETIME_239POINT5);

    ADC_RegularChannel_Config(ADC_CHANNEL_4, 3, ADC_SAMPLETIME_239POINT5);
    ADC_RegularChannel_Config(ADC_CHANNEL_1, 4, ADC_SAMPLETIME_239POINT5);

    ADC_DMA_Enable(ENABLE);	 
    
    ADC_Enable(ENABLE); 
		
    ADC_Calibration();
    
    ADC_SoftwareStartConv_Enable(ENABLE);  
}
Esempio n. 9
0
/**
  * @brief  Configure the TIMER peripheral.
  * @param  None
  * @retval None
  */
void TIMER_Configuration(void)
{
    /* TIMER1 DMA Transfer example -------------------------------------------------
    TIMER1CLK = 72MHz, Prescaler = 72 
    TIMER1 counter clock = SystemCoreClock/72 = 1MHz.

    The objective is to configure TIMER1 channel 1 to generate PWM
    signal with a frequency equal to 1KHz and a variable duty cycle(25%,50%,75%) that is 
    changed by the DMA after a specific number of Update DMA request.

    The number of this repetitive requests is defined by the TIMER1 Repetition counter,
    each 2 Update Requests, the TIMER1 Channel 1 Duty Cycle changes to the next new 
    value defined by the buffer . 
    -----------------------------------------------------------------------------*/
    TIMER_BaseInitPara TIMER_TimeBaseStructure;
    TIMER_OCInitPara  TIMER_OCInitStructure;
    /* TIMERS clock enable */
    RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_TIMER1|RCC_APB2PERIPH_TIMER15|RCC_APB2PERIPH_TIMER16|RCC_APB2PERIPH_TIMER17,ENABLE);
    RCC_APB1PeriphClock_Enable(RCC_APB1PERIPH_TIMER2|RCC_APB1PERIPH_TIMER3|RCC_APB1PERIPH_TIMER6|RCC_APB1PERIPH_TIMER14,ENABLE);

    /* TIMER1  configuration */
    TIMER_DeInit(TIMER1);
    TIMER_TimeBaseStructure.TIMER_Prescaler         = 71;
    TIMER_TimeBaseStructure.TIMER_CounterMode       = TIMER_COUNTER_UP;
    TIMER_TimeBaseStructure.TIMER_Period            = 999;
    TIMER_TimeBaseStructure.TIMER_ClockDivision     = TIMER_CDIV_DIV1;
    TIMER_TimeBaseStructure.TIMER_RepetitionCounter = 1;
    TIMER_BaseInit(TIMER1,&TIMER_TimeBaseStructure);

    /* CH1 Configuration in PWM mode */
    TIMER_OCInitStructure.TIMER_OCMode       = TIMER_OC_MODE_PWM1;
    TIMER_OCInitStructure.TIMER_OCPolarity   = TIMER_OC_POLARITY_HIGH;
    TIMER_OCInitStructure.TIMER_OCNPolarity  = TIMER_OCN_POLARITY_HIGH;
    TIMER_OCInitStructure.TIMER_OutputState  = TIMER_OUTPUT_STATE_ENABLE;
    TIMER_OCInitStructure.TIMER_OutputNState = TIMER_OUTPUTN_STATE_ENABLE;
    TIMER_OCInitStructure.TIMER_OCIdleState  = TIMER_OC_IDLE_STATE_SET;
    TIMER_OCInitStructure.TIMER_OCNIdleState = TIMER_OCN_IDLE_STATE_RESET;
     
    TIMER_OCInitStructure.TIMER_Pulse = buffer[0];
    TIMER_OC1_Init(TIMER1, &TIMER_OCInitStructure);
    TIMER_OC1_Preload(TIMER1,TIMER_OC_PRELOAD_DISABLE);

    /* TIMER1 output enable */
    TIMER_CtrlPWMOutputs(TIMER1,ENABLE);
    /* Auto-reload preload enable */
    TIMER_CARLPreloadConfig(TIMER1,ENABLE);
    /* TIMER1 Update DMA Request enable */
    TIMER_DMACmd( TIMER1, TIMER_DMA_UPDATE, ENABLE);
    /* TIMER enable counter*/
    TIMER_Enable( TIMER1, ENABLE );
}
Esempio n. 10
0
/** 
  * @brief  Configure RCC Clock.
  * @param  None
  * @retval None
  */
void RCC_Configuration(void)
{
    RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_GPIOA , ENABLE);
    RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_GPIOB , ENABLE);
    RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_GPIOC , ENABLE);
    RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_GPIOD , ENABLE);
    RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_GPIOE , ENABLE);
    RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_AF    , ENABLE);

    RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_USART1, ENABLE);
    RCC_AHBPeriphClock_Enable(RCC_AHBPERIPH_EXMC, ENABLE);
}
Esempio n. 11
0
void exti_charging_deinit()
{
    EXTI_InitPara   EXTI_InitStructure;
    RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_CFG, ENABLE);
    /* Connect key EXTI Line to key GPIO Pin */
    SYSCFG_EXTILine_Config(CHARGING_EXTI_GPIO, CHARGING_EXTI_PIN);
    /* Configure increase key EXTI line */
    EXTI_InitStructure.EXTI_LINE = CHARGING_EXTILINE;
    EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
    EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
    EXTI_InitStructure.EXTI_LINEEnable = DISABLE;
    EXTI_Init(&EXTI_InitStructure);
    EXTI_ClearIntBitState(CHARGING_EXTILINE);
}
Esempio n. 12
0
/**
  * @brief  Configure the TIMER peripheral.
  * @param  None
  * @retval None
  */
void TIMER_Configuration(void)
{
    /* ---------------------------------------------------------------
    TIMER2 Configuration: 
    TIMER2CLK = SystemCoreClock / 36000 = 2K,
    And generate 3 signals with 3 different delays:
    TIMER2_CH1 delay = 4000/2000  = 2s
    TIMER2_CH2 delay = 8000/2000  = 4s
    TIMER2_CH3 delay = 12000/2000 = 6s
    --------------------------------------------------------------- */
    TIMER_BaseInitPara TIMER_TimeBaseStructure;
    TIMER_OCInitPara  TIMER_OCInitStructure;

    /* TIMERS clock enable */
    RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_TIMER1|RCC_APB2PERIPH_TIMER15|RCC_APB2PERIPH_TIMER16|RCC_APB2PERIPH_TIMER17,ENABLE);
    RCC_APB1PeriphClock_Enable(RCC_APB1PERIPH_TIMER2|RCC_APB1PERIPH_TIMER3|RCC_APB1PERIPH_TIMER6|RCC_APB1PERIPH_TIMER14,ENABLE);

    /* TIMER2  configuration */
    TIMER_DeInit(TIMER2);
    TIMER_TimeBaseStructure.TIMER_Prescaler     = 35999;
    TIMER_TimeBaseStructure.TIMER_CounterMode   = TIMER_COUNTER_UP;
    TIMER_TimeBaseStructure.TIMER_Period        = 19999;
    TIMER_TimeBaseStructure.TIMER_ClockDivision = TIMER_CDIV_DIV1;
    TIMER_BaseInit(TIMER2,&TIMER_TimeBaseStructure);

    /* CH1,CH2 and CH3 Configuration in OC_ACTIVE mode */
    TIMER_OCInitStructure.TIMER_OCMode      = TIMER_OC_MODE_ACTIVE;
    TIMER_OCInitStructure.TIMER_OCPolarity  = TIMER_OC_POLARITY_HIGH;
    TIMER_OCInitStructure.TIMER_OutputState = TIMER_OUTPUT_STATE_ENABLE;

      
    TIMER_OCInitStructure.TIMER_Pulse = 3999;
    TIMER_OC1_Init(TIMER2, &TIMER_OCInitStructure);
    TIMER_OC1_Preload(TIMER2,TIMER_OC_PRELOAD_DISABLE);

    TIMER_OCInitStructure.TIMER_Pulse = 7999;
    TIMER_OC2_Init(TIMER2, &TIMER_OCInitStructure);
    TIMER_OC2_Preload(TIMER2,TIMER_OC_PRELOAD_DISABLE);

    TIMER_OCInitStructure.TIMER_Pulse = 11999;
    TIMER_OC3_Init(TIMER2, &TIMER_OCInitStructure);
    TIMER_OC3_Preload(TIMER2,TIMER_OC_PRELOAD_DISABLE);

    /* Auto-reload preload enable */
    TIMER_CARLPreloadConfig(TIMER2,ENABLE);
    /* TIMER enable counter*/
    TIMER_Enable( TIMER2, ENABLE );
}
Esempio n. 13
0
/**
  * @brief  Init SPI1.
  * @param  None
  * @retval None
  */
static void SPI1_Init(void)
{
    SPI_InitPara  SPI_InitStructure;
    {
        /* Configure the GPIO ports */
        GPIO_InitPara GPIO_InitStructure;

        /* Connect pin to Periph */
        GPIO_PinAFConfig( GPIOB , GPIO_PINSOURCE3, GPIO_AF_0 );
        GPIO_PinAFConfig( GPIOB , GPIO_PINSOURCE4, GPIO_AF_0 );
        GPIO_PinAFConfig( GPIOB , GPIO_PINSOURCE5, GPIO_AF_0 );

        /* Configure pins as AF pushpull */
        GPIO_InitStructure.GPIO_Pin   = GPIO_PIN_3|
                                        GPIO_PIN_4|
                                        GPIO_PIN_5;
        GPIO_InitStructure.GPIO_Mode  = GPIO_MODE_AF;
        GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_50MHZ;
        GPIO_InitStructure.GPIO_OType = GPIO_OTYPE_PP;
        GPIO_InitStructure.GPIO_PuPd  = GPIO_PUPD_NOPULL;
        GPIO_Init( GPIOB , &GPIO_InitStructure);

        GPIO_InitStructure.GPIO_Mode  = GPIO_MODE_OUT;

        GPIO_InitStructure.GPIO_Pin   = GPIO_PIN_3|
                                        GPIO_PIN_4;
        GPIO_Init( GPIOC , &GPIO_InitStructure);

        GPIO_InitStructure.GPIO_Pin   = GPIO_PIN_5 ;
        GPIO_Init( GPIOF , &GPIO_InitStructure);
        GPIO_SetBits(GPIOF,GPIO_PIN_5);
    }

    RCC_APB2PeriphClock_Enable( RCC_APB2PERIPH_SPI1, ENABLE );

    SPI_InitStructure.SPI_TransType   = SPI_TRANSTYPE_FULLDUPLEX;
    SPI_InitStructure.SPI_Mode        = SPI_MODE_MASTER;
    SPI_InitStructure.SPI_FrameFormat = SPI_FRAMEFORMAT_8BIT;
    SPI_InitStructure.SPI_SCKPL       = SPI_SCKPL_HIGH;
    SPI_InitStructure.SPI_SCKPH       = SPI_SCKPH_2EDGE;
    SPI_InitStructure.SPI_SWNSSEN     = SPI_SWNSS_SOFT;
    SPI_InitStructure.SPI_PSC         = SPI_PSC_2;
    SPI_InitStructure.SPI_FirstBit    = SPI_FIRSTBIT_MSB;
    SPI_InitStructure.SPI_CRCPOL      = 7;
    SPI_Init(SPI1, &SPI_InitStructure);

    SPI_Enable(SPI1, ENABLE);
}
Esempio n. 14
0
void KT_I2C_Init(void) {
	GPIO_InitPara GPIO_InitStructure;
	
	RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_GPIOB,ENABLE);

    GPIO_InitStructure.GPIO_Pin   = GPIO_PIN_6 | GPIO_PIN_7;
    GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_50MHZ;
    GPIO_InitStructure.GPIO_Mode  = GPIO_MODE_OUT_OD;

    GPIO_Init(GPIOB,&GPIO_InitStructure);
	
	SDA_1;
	SCL_1;
	Delay10us();
	Delay10us();
}
Esempio n. 15
0
void LED_config(void)
{
    GPIO_InitPara GPIO_InitStructure;
    
    /* Enable GPIOC, GPIOE */
    RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_GPIOC | RCC_APB2PERIPH_GPIOE, ENABLE);
      
    /* Configure the GPIO_LED pin */
    GPIO_InitStructure.GPIO_Pin = GPIO_LED1 | GPIO_LED2 ;
    GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUT_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_50MHZ;
    GPIO_Init(GPIOC, &GPIO_InitStructure);
    
    GPIO_InitStructure.GPIO_Pin =GPIO_LED3 | GPIO_LED4;
    GPIO_Init(GPIOE, &GPIO_InitStructure);
}
Esempio n. 16
0
/**
  * @brief  Configure the TIMER peripheral.
  * @param  None
  * @retval None
  */
void TIMER_Configuration(void)
{
    /* -----------------------------------------------------------------------
    TIMER2 Configuration: generate 3 PWM signals with 3 different duty cycles:
    TIMER2CLK = SystemCoreClock / 72 = 1MHz

    TIMER2 Channel2 duty cycle = (4000/ 16000)* 100  = 25%
    TIMER2 Channel3 duty cycle = (8000/ 16000)* 100  = 50%
    TIMER2 Channel4 duty cycle = (12000/ 16000)* 100 = 75%
    ----------------------------------------------------------------------- */
    TIMER_BaseInitPara TIMER_TimeBaseStructure;
    TIMER_OCInitPara  TIMER_OCInitStructure;

    /* TIMERS clock enable */
    RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_TIMER1|RCC_APB2PERIPH_TIMER15|RCC_APB2PERIPH_TIMER16|RCC_APB2PERIPH_TIMER17,ENABLE);
    RCC_APB1PeriphClock_Enable(RCC_APB1PERIPH_TIMER2|RCC_APB1PERIPH_TIMER3|RCC_APB1PERIPH_TIMER6|RCC_APB1PERIPH_TIMER14,ENABLE);

    /* TIMER2  configuration */
    TIMER_DeInit(TIMER2);
    TIMER_TimeBaseStructure.TIMER_Prescaler     = 71;
    TIMER_TimeBaseStructure.TIMER_CounterMode   = TIMER_COUNTER_UP;
    TIMER_TimeBaseStructure.TIMER_Period        = 15999;
    TIMER_TimeBaseStructure.TIMER_ClockDivision = TIMER_CDIV_DIV1;
    TIMER_BaseInit(TIMER2,&TIMER_TimeBaseStructure);

    /* CH2,CH3 and CH4 Configuration in PWM mode */
    TIMER_OCInitStructure.TIMER_OCMode      = TIMER_OC_MODE_PWM1;
    TIMER_OCInitStructure.TIMER_OCPolarity  = TIMER_OC_POLARITY_HIGH;
    TIMER_OCInitStructure.TIMER_OutputState = TIMER_OUTPUT_STATE_ENABLE;

    TIMER_OCInitStructure.TIMER_Pulse = 3999;
    TIMER_OC2_Init(TIMER2, &TIMER_OCInitStructure);
    TIMER_OC2_Preload(TIMER2,TIMER_OC_PRELOAD_DISABLE);

    TIMER_OCInitStructure.TIMER_Pulse = 7999;
    TIMER_OC3_Init(TIMER2, &TIMER_OCInitStructure);
    TIMER_OC3_Preload(TIMER2,TIMER_OC_PRELOAD_DISABLE);

    TIMER_OCInitStructure.TIMER_Pulse = 11999;
    TIMER_OC4_Init(TIMER2, &TIMER_OCInitStructure);
    TIMER_OC4_Preload(TIMER2,TIMER_OC_PRELOAD_DISABLE);

    /* Auto-reload preload enable */
    TIMER_CARLPreloadConfig(TIMER2,ENABLE);
    /* TIMER enable counter*/
    TIMER_Enable( TIMER2, ENABLE );
}
Esempio n. 17
0
/**
  * @brief  Configure the LED GPIO.
  * @param  None
  * @retval None
  */
void LED_Init(void)
{
    GPIO_InitPara GPIO_InitStructure;
    
    /* Enable GPIOC and GPIOE clock */
    RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_GPIOC | RCC_APB2PERIPH_GPIOE, ENABLE);
    
    /* Configure the four LEDs GPIO */
    GPIO_InitStructure.GPIO_Pin = GPIO_PIN_0 | GPIO_PIN_2;
    GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUT_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_50MHZ;
    GPIO_Init(GPIOC, &GPIO_InitStructure);
    
    GPIO_InitStructure.GPIO_Pin = GPIO_PIN_0 | GPIO_PIN_1;
    GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUT_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_50MHZ;
    GPIO_Init(GPIOE, &GPIO_InitStructure);
}
Esempio n. 18
0
void exti_charging_init()
{
    NVIC_InitPara   NVIC_InitStructure;
    EXTI_InitPara   EXTI_InitStructure;

    RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_CFG, ENABLE);
    /* Connect key EXTI Line to key GPIO Pin */
    SYSCFG_EXTILine_Config(CHARGING_EXTI_GPIO, CHARGING_EXTI_PIN);

    /* Configure increase key EXTI line */
    EXTI_ClearIntBitState(CHARGING_EXTILINE);
    EXTI_InitStructure.EXTI_LINE = CHARGING_EXTILINE;
    EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
    EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
    EXTI_InitStructure.EXTI_LINEEnable = ENABLE;
    EXTI_Init(&EXTI_InitStructure);
    EXTI_ClearIntBitState(CHARGING_EXTILINE);

    NVIC_InitStructure.NVIC_IRQ = CHARGING_EXTI_IRQ;			//使能按键所在的外部中断通道
    NVIC_InitStructure.NVIC_IRQPreemptPriority = 0x01;	//抢占优先级1
    NVIC_InitStructure.NVIC_IRQSubPriority = 0x00;					//子优先级1
    NVIC_InitStructure.NVIC_IRQEnable = ENABLE;								//使能外部中断通道
    NVIC_Init(&NVIC_InitStructure);  	  //根据NVIC_InitStruct中指定的参数初始化外设NVIC寄存器
}
Esempio n. 19
0
void pwm_init(void)
{
	
    GPIO_InitPara GPIO_InitStructure;

	// timer 3 pin PB1 config ( ch4 )
    GPIO_InitStructure.GPIO_Pin = GPIO_PIN_1;
    GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF;
    GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_50MHZ;
    GPIO_InitStructure.GPIO_OType = GPIO_OTYPE_PP;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PUPD_PULLDOWN;
    GPIO_Init(GPIOB,&GPIO_InitStructure);
		
    GPIO_PinAFConfig(GPIOB,GPIO_PINSOURCE1,GPIO_AF_1);
	
	// GPIO pins PA8 , 9 ,10 setup ( Timer1 ch 1 , 2 , 3)
	  GPIO_InitStructure.GPIO_Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10;

    GPIO_Init(GPIOA,&GPIO_InitStructure);
		
    GPIO_PinAFConfig(GPIOA,GPIO_PINSOURCE8,GPIO_AF_2);
	  GPIO_PinAFConfig(GPIOA,GPIO_PINSOURCE9,GPIO_AF_2);
		GPIO_PinAFConfig(GPIOA,GPIO_PINSOURCE10,GPIO_AF_2);
	
    TIMER_BaseInitPara TIM_TimeBaseStructure;

    RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_TIMER1,ENABLE);
    RCC_APB1PeriphClock_Enable(RCC_APB1PERIPH_TIMER3,ENABLE);

// TIMER3 for pins A8 A9 A10

    TIM_TimeBaseStructure.TIMER_Prescaler = TIMER_PRESCALER - 1;  //
    TIM_TimeBaseStructure.TIMER_CounterMode = TIMER_COUNTER_UP;
    TIM_TimeBaseStructure.TIMER_Period = PWMTOP;
    TIM_TimeBaseStructure.TIMER_ClockDivision = TIMER_CDIV_DIV1;
    TIMER_BaseInit(TIMER3,&TIM_TimeBaseStructure);
		

 //Ch1 , 2 , 3 
    TIM_OCInitStructure.TIMER_OCMode = TIMER_OC_MODE_PWM1;
    TIM_OCInitStructure.TIMER_OCPolarity = OUT_POLARITY;
    TIM_OCInitStructure.TIMER_OutputState = TIMER_OUTPUT_STATE_ENABLE;
    TIM_OCInitStructure.TIMER_OCIdleState = TIMER_OC_IDLE_STATE_RESET;
		
    TIM_OCInitStructure.TIMER_Pulse = 0;
    TIMER_OC4_Init(TIMER3, &TIM_OCInitStructure);

	TIMER_CtrlPWMOutputs(TIMER3,ENABLE);

    TIMER_CARLPreloadConfig(TIMER3,ENABLE);

    TIMER_Enable( TIMER3, ENABLE );
		
    TIMER_BaseInit(TIMER1,&TIM_TimeBaseStructure);

    TIMER_OC1_Init(TIMER1, &TIM_OCInitStructure);

    TIMER_OC2_Init(TIMER1, &TIM_OCInitStructure);

    TIMER_OC3_Init(TIMER1, &TIM_OCInitStructure);
		
	TIMER_CtrlPWMOutputs(TIMER1,ENABLE);	
		
    TIMER_CARLPreloadConfig(TIMER1,ENABLE);

	TIMER_OC1_Preload(TIMER1,ESC_PRELOAD);
	TIMER_OC2_Preload(TIMER1,ESC_PRELOAD);
	TIMER_OC3_Preload(TIMER1,ESC_PRELOAD);
	TIMER_OC4_Preload(TIMER3,ESC_PRELOAD);
	
  TIMER_Enable( TIMER1, ENABLE );
}
Esempio n. 20
0
/**
  * @brief  Configures system clocks.
  * @param  None
  * @retval None
  */
void RCC_Configuration(void)
{
    /* GPIOA, GPIOC and AF clocks enable */
    RCC_APB2PeriphClock_Enable( RCC_APB2PERIPH_GPIOA | RCC_APB2PERIPH_GPIOC |
                                RCC_APB2PERIPH_AF, ENABLE);
}
Esempio n. 21
0
void pwm_init(void)
{
	GPIO_InitPara GPIO_InitStructure;


//pin A0 TM2_ch1
	GPIO_InitStructure.GPIO_Pin = GPIO_PIN_1;
	GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF;
	GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_50MHZ;
	GPIO_InitStructure.GPIO_OType = GPIO_OTYPE_PP;
	GPIO_InitStructure.GPIO_PuPd = GPIO_PUPD_PULLDOWN;
	GPIO_Init(GPIOA, &GPIO_InitStructure);

	GPIO_PinAFConfig(GPIOA, GPIO_PINSOURCE1, GPIO_AF_2);


	TIMER_BaseInitPara TIM_TimeBaseStructure;

	RCC_APB1PeriphClock_Enable(RCC_APB1PERIPH_TIMER2 | 
															RCC_APB1PERIPH_TIMER14 |
																RCC_APB1PERIPH_TIMER3, ENABLE);
	
	RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_TIMER1, ENABLE);

// timer 2
	TIM_TimeBaseStructure.TIMER_Prescaler = TIMER_PRESCALER - 1;	//
	TIM_TimeBaseStructure.TIMER_CounterMode = TIMER_COUNTER_CENTER_ALIGNED2;
	TIM_TimeBaseStructure.TIMER_Period = PWMTOP;
	TIM_TimeBaseStructure.TIMER_ClockDivision = TIMER_CDIV_DIV1;
// init timer 2
	TIMER_BaseInit(TIMER2, &TIM_TimeBaseStructure);

	TIM_OCInitStructure.TIMER_OCMode = TIMER_OC_MODE_PWM1;
	TIM_OCInitStructure.TIMER_OCPolarity = TIMER_OC_POLARITY_HIGH;
	TIM_OCInitStructure.TIMER_OutputState = TIMER_OUTPUT_STATE_ENABLE;
	TIM_OCInitStructure.TIMER_OCIdleState = TIMER_OC_IDLE_STATE_RESET;

	TIM_OCInitStructure.TIMER_Pulse = 0;

	TIMER_OC2_Init(TIMER2, &TIM_OCInitStructure);

	TIMER_CtrlPWMOutputs(TIMER2, ENABLE);

	TIMER_CARLPreloadConfig(TIMER2, ENABLE);


	TIMER_OC2_Preload(TIMER2, TIMER_OC_PRELOAD_DISABLE);


	// pin A3

	GPIO_InitStructure.GPIO_Pin = GPIO_PIN_3;
	GPIO_Init(GPIOA, &GPIO_InitStructure);

	GPIO_PinAFConfig(GPIOA, GPIO_PINSOURCE3, GPIO_AF_2);

	TIMER_OC4_Init(TIMER2, &TIM_OCInitStructure);


	TIMER_OC4_Preload(TIMER2, TIMER_OC_PRELOAD_DISABLE);

//   TIMER_Enable( TIMER2, ENABLE );

// timer 1 ch3 , ch1 
// pins A10 , A8         
	GPIO_InitStructure.GPIO_Pin = GPIO_PIN_10 | GPIO_PIN_8;

	GPIO_Init(GPIOA, &GPIO_InitStructure);

	GPIO_PinAFConfig(GPIOA, GPIO_PINSOURCE10, GPIO_AF_2);
	GPIO_PinAFConfig(GPIOA, GPIO_PINSOURCE8, GPIO_AF_2);


// timer 1

// init timer 1
	TIMER_BaseInit(TIMER1, &TIM_TimeBaseStructure);

	TIM_OCInitStructure.TIMER_Pulse = 0;

	TIMER_OC3_Init(TIMER1, &TIM_OCInitStructure);

	TIMER_OC1_Init(TIMER1, &TIM_OCInitStructure);

	TIMER_CtrlPWMOutputs(TIMER1, ENABLE);

	TIMER_CARLPreloadConfig(TIMER1, ENABLE);


	TIMER_OC3_Preload(TIMER1, TIMER_OC_PRELOAD_DISABLE);

	TIMER_OC1_Preload(TIMER1, TIMER_OC_PRELOAD_DISABLE);


// bridge dir 2
///////////////

	//pin A9 TM1_ch2
	GPIO_InitStructure.GPIO_Pin = GPIO_PIN_9;

	GPIO_Init(GPIOA, &GPIO_InitStructure);

	GPIO_PinAFConfig(GPIOA, GPIO_PINSOURCE9, GPIO_AF_2);

// timer 1

// init timer 1
	TIMER_BaseInit(TIMER1, &TIM_TimeBaseStructure);

	TIM_OCInitStructure.TIMER_Pulse = 0;

	TIMER_OC2_Init(TIMER2, &TIM_OCInitStructure);

	TIMER_CtrlPWMOutputs(TIMER1, ENABLE);

	TIMER_CARLPreloadConfig(TIMER1, ENABLE);


	TIMER_OC2_Preload(TIMER1, TIMER_OC_PRELOAD_DISABLE);



// timer 3 PB1 af1 ch4

	GPIO_InitStructure.GPIO_Pin = GPIO_PIN_1;

	GPIO_Init(GPIOB, &GPIO_InitStructure);

	GPIO_PinAFConfig(GPIOB, GPIO_PINSOURCE1, GPIO_AF_1);


// timer 3

// init timer 3
	TIMER_BaseInit(TIMER3, &TIM_TimeBaseStructure);

	TIM_OCInitStructure.TIMER_Pulse = 0;

	TIMER_OC4_Init(TIMER3, &TIM_OCInitStructure);

	TIMER_CtrlPWMOutputs(TIMER3, ENABLE);

	TIMER_CARLPreloadConfig(TIMER3, ENABLE);


	TIMER_OC4_Preload(TIMER3, TIMER_OC_PRELOAD_DISABLE);

// A0
// Timer2 ch1

	GPIO_InitStructure.GPIO_Pin = GPIO_PIN_0;

	GPIO_Init(GPIOA, &GPIO_InitStructure);

	GPIO_PinAFConfig(GPIOA, GPIO_PINSOURCE0, GPIO_AF_2);


// timer 2

// init timer 2
	TIMER_BaseInit(TIMER2, &TIM_TimeBaseStructure);

	TIM_OCInitStructure.TIMER_Pulse = 0;

	TIMER_OC1_Init(TIMER2, &TIM_OCInitStructure);

	TIMER_CtrlPWMOutputs(TIMER2, ENABLE);

	TIMER_CARLPreloadConfig(TIMER2, ENABLE);


	TIMER_OC1_Preload(TIMER2, TIMER_OC_PRELOAD_DISABLE);

// PA2 tm2 ch3

	GPIO_InitStructure.GPIO_Pin = GPIO_PIN_2;

	GPIO_Init(GPIOA, &GPIO_InitStructure);

	GPIO_PinAFConfig(GPIOA, GPIO_PINSOURCE2, GPIO_AF_2);


	TIMER_OC3_Init(TIMER2, &TIM_OCInitStructure);

	TIMER_OC3_Preload(TIMER2, TIMER_OC_PRELOAD_DISABLE);



	TIMER_Enable(TIMER3, ENABLE);

	TIMER_Enable(TIMER1, ENABLE);

	TIMER_Enable(TIMER2, ENABLE);


}
Esempio n. 22
0
/**    
  * @brief  RCC configuration.    
  * @param  None    
  * @retval None    
  */ 
void RCC_Configuration()
{
     RCC_APB2PeriphClock_Enable( RCC_APB2PERIPH_GPIOA | RCC_APB2PERIPH_GPIOB 
                               | RCC_APB2PERIPH_GPIOC |RCC_APB2PERIPH_GPIOE, ENABLE);
     RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_SPI1,ENABLE);
}