//ÊäÈ벶»ñÅäÖÃ
void capture_config(void)
{
    TIM_ICInitTypeDef TIM_ICInitStructure;

    gpio_af_pp_up_init(GPIOB, GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_9);//CH1|CH2|CH4
    GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_TIM4);
    GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_TIM4);
    GPIO_PinAFConfig(GPIOB, GPIO_PinSource9, GPIO_AF_TIM4);

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);

    TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Falling;
    TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
    TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
    TIM_ICInitStructure.TIM_ICFilter = 0x0;

    TIM_ICInitStructure.TIM_Channel = TIM_Channel_1;
    TIM_ICInit(TIM4, &TIM_ICInitStructure);

    TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;
    TIM_ICInit(TIM4, &TIM_ICInitStructure);

    TIM_ICInitStructure.TIM_Channel = TIM_Channel_4;
    TIM_ICInit(TIM4, &TIM_ICInitStructure);

    TIM_Cmd(TIM4, ENABLE);
    TIM_ITConfig(TIM4, TIM_IT_CC1, ENABLE);
    TIM_ITConfig(TIM4, TIM_IT_CC2, ENABLE);
    TIM_ITConfig(TIM4, TIM_IT_CC4, ENABLE);

    nvic_config(TIM4_IRQn, 2);
}
Beispiel #2
0
//--------------
//main loop
int main(void)
{

	int i=0;
	for(i=0;i<100000ul;i++);


	rcc_config();
	nvic_config();
	gpio_config();
	usart_config();
	USART_puts(USART1, "USART BT initialization complete!\r\n"); // just send a message to indicate that it works

	MPU6050_I2C_Init();
	MPU6050_Initialize();
	if( MPU6050_TestConnection() == 1){
	    // connection success
		USART_puts(USART1, "I2C IMU connection initialization complete!\r\n");
	}else{
	    // connection failed
		USART_puts(USART1, "I2C initialization failed!\r\n");
	}

	//sysTick_Config_Mod(SysTick_CLKSource_HCLK_Div8, 10500000ul); // interruption every 1/2sec from systick
	sysTick_Config_Mod(SysTick_CLKSource_HCLK_Div8, 840000ul); // interruption every 0.04sec from systick


    while(1)
    {

    }
}
Beispiel #3
0
/*!
    \brief      main routine
    \param[in]  none
    \param[out] none
    \retval     none
*/
int main(void)
{
    /* system clocks configuration */
    rcu_config();

    /* GPIO configuration */
    gpio_config();

    /* USB device configuration */
    usbd_core_init(&usb_device_dev);

    /* NVIC configuration */
    nvic_config();

    /* enabled USB pull-up */
    gpio_bit_set(USB_PULLUP, USB_PULLUP_PIN);

    /* now the usb device is connected */
    usb_device_dev.status = USBD_CONNECTED;

    while (1)
    {
        if (USBD_CONFIGURED == usb_device_dev.status) {
            cdc_acm_data_receive(&usb_device_dev);
            if (0 != receive_length) {
                if (1 == packet_sent) {
                    cdc_acm_data_send(&usb_device_dev, receive_length);
                    receive_length = 0;
                }
            }
        }
    }
}
Beispiel #4
0
/*!
    \brief      main function
    \param[in]  none
    \param[out] none
    \retval     none
*/
int main(void)
{
    can_parameter_struct            can_init_parameter;
    can_filter_parameter_struct     can_filter_parameter;

    receive_flag = RESET;
    /* configure Tamper key */
    gd_eval_keyinit(KEY_TAMPER, KEY_MODE_GPIO);
    /* configure GPIO */
    gpio_config();
    /* configure USART */
    gd_eval_COMinit(EVAL_COM2);
    /* configure NVIC */
    nvic_config();
    /* configure leds */
    led_config();
    /* set all leds off */
    gd_eval_ledoff(LED1);
    gd_eval_ledoff(LED2);
    gd_eval_ledoff(LED3);
    gd_eval_ledoff(LED4);
    /* initialize CAN */
    can_networking_init(can_init_parameter, can_filter_parameter);
    /* enable phy */
#ifdef CAN0_USED 
    can_phy_enable(CANX);
#endif
    /* enable CAN receive FIFO0 not empty interrupt */
    can_interrupt_enable(CANX, CAN_INTEN_RFNEIE0);
    
    /* initialize transmit message */
    transmit_message.can_tx_sfid = 0x321;
    transmit_message.can_tx_efid = 0x01;
    transmit_message.can_tx_ft = CAN_FT_DATA;
    transmit_message.can_tx_ff = CAN_FF_STANDARD;
    transmit_message.can_tx_dlen = 1;
    printf("please press the Tamper key to transmit data!\r\n");
    while(1){
        /* waiting for the Tamper key pressed */
        while(0 == gd_eval_keygetstate(KEY_TAMPER)){
            /* if transmit_number is 0x10, set it to 0x00 */
            if(transmit_number == 0x10){
                transmit_number = 0x00;
            }else{
                transmit_message.can_tx_data[0] = transmit_number++;
                printf("transmit data: %x\r\n", transmit_message.can_tx_data[0]);
                /* transmit message */
                can_transmit_message(CANX, &transmit_message);
                delay();
                /* waiting for Tamper key up */
                while(0 == gd_eval_keygetstate(KEY_TAMPER));
            }
        }
        if(SET == receive_flag){
            gd_eval_ledtoggle(LED1);
            receive_flag = RESET;
            printf("recive data: %x\r\n", receive_message.can_rx_data[0]);
        }
    } 
}
Beispiel #5
0
//输入捕获配置
void capture_config(void)
{
	TIM_ICInitTypeDef TIM_ICInitStructure;
	
	gpio_af_pp_up_init(GPIOC, GPIO_Pin_8|GPIO_Pin_9);//CH3|CH4
	GPIO_PinAFConfig(GPIOC, GPIO_PinSource8, GPIO_AF_TIM3);
	GPIO_PinAFConfig(GPIOC, GPIO_PinSource9, GPIO_AF_TIM3);
	
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
	
	TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_BothEdge;
	TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
	TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
	TIM_ICInitStructure.TIM_ICFilter = 10;
	
	TIM_ICInitStructure.TIM_Channel = TIM_Channel_3;
	TIM_ICInit(TIM3, &TIM_ICInitStructure);
	
	TIM_ICInitStructure.TIM_Channel = TIM_Channel_4;
	TIM_ICInit(TIM3, &TIM_ICInitStructure);
	
	TIM_Cmd(TIM3, ENABLE);
	TIM_ITConfig(TIM3, TIM_IT_CC3, ENABLE);
	TIM_ITConfig(TIM3, TIM_IT_CC4, ENABLE);
	
	nvic_config(TIM3_IRQn, 0);
	TIM7_init(500, 8400);
}
Beispiel #6
0
void usart6_init(uint32_t baudRate)
{
	USART_InitTypeDef USART_InitStructure;
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART6, ENABLE);
	
	GPIO_PinAFConfig(GPIOC, GPIO_PinSource6, GPIO_AF_USART6);
    GPIO_PinAFConfig(GPIOC, GPIO_PinSource7, GPIO_AF_USART6);
	gpio_af_pp_up_init(GPIOC, GPIO_Pin_6|GPIO_Pin_7);
	
	USART_InitStructure.USART_BaudRate = baudRate;
	USART_InitStructure.USART_WordLength = USART_WordLength_8b;
	USART_InitStructure.USART_StopBits = USART_StopBits_1;
	USART_InitStructure.USART_Parity = USART_Parity_No;
	USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
	USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
	USART_Init(USART6, &USART_InitStructure); 
#ifndef DEBUG_HAHA
	USART_ITConfig(USART6, USART_IT_RXNE,ENABLE);
#endif
	USART_Cmd(USART6, ENABLE);
	USART_ClearFlag(USART6, USART_FLAG_TC);
#ifndef DEBUG_HAHA
	nvic_config(USART6_IRQn, 4);
#endif
}
Beispiel #7
0
/**
  * @brief   Main program
  * @param  None
  * @retval None
  */
int main(void)
{
	nvic_config();
	uart_init();
	printf("hello!welcome to F4...\r\n ");
	while(1)
	{

	}
}
Beispiel #8
0
//定时器触发的ADC配置
void adc_tim_trig_config(uint32_t period, uint32_t prescaler)
{
	ADC_CommonInitTypeDef ADC_CommonInitStructure;
	ADC_InitTypeDef  ADC_InitStructure;
	TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
	TIM_OCInitTypeDef  TIM_OCInitStructure;
	
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE);
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
	
	gpio_an_no_init(GPIOC, GPIO_Pin_5);
	
	ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;	//独立模式
	ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;	//两个采样阶段之间的延迟5个时钟
	ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled; 		//DMA失能
	ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div4;	//ADCCLK=PCLK2/4=84/4=21Mhz
	ADC_CommonInit(&ADC_CommonInitStructure);
	
	ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;	//12位模式
	ADC_InitStructure.ADC_ScanConvMode = DISABLE;			//关闭扫描模式	
	ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;		//关闭连续转换
	ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_Rising;	//外部触发上升沿
	ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T2_CC2;
	ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;	//右对齐	
	ADC_InitStructure.ADC_NbrOfConversion = 1;				//规则序列中有1个转换
	ADC_Init(ADC1, &ADC_InitStructure);
	
	ADC_RegularChannelConfig(ADC1, ADC_Channel_15, 1, ADC_SampleTime_84Cycles );	//设置通道5采样顺序为1, 采样时间为84个周期	
	ADC_ITConfig(ADC1, ADC_IT_EOC, ENABLE);
	ADC_Cmd(ADC1, ENABLE);
	
	nvic_config(ADC_IRQn, 2);
	
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
	
	TIM_TimeBaseStructure.TIM_Period = period-1;
	TIM_TimeBaseStructure.TIM_Prescaler = prescaler-1;
	TIM_TimeBaseStructure.TIM_ClockDivision = 0;
	TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
	TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
	
	TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
	TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
	TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
	TIM_OCInitStructure.TIM_Pulse = period/2;
	TIM_OC2Init(TIM2, &TIM_OCInitStructure);
	
	TIM_Cmd(TIM2, ENABLE);    
	TIM_InternalClockConfig(TIM2);  
	TIM_OC2PreloadConfig(TIM2, TIM_OCPreload_Enable);  
	TIM_UpdateDisableConfig(TIM2, DISABLE); 
}
void micros_time_16_1_init(void)
{
	TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
	
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM14, ENABLE);
	
	TIM_TimeBaseStructure.TIM_Period = 0XFFFF;    
    TIM_TimeBaseStructure.TIM_Prescaler = (84-1);                
    TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;             
    TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
    TIM_TimeBaseInit(TIM14, &TIM_TimeBaseStructure);  
    TIM_Cmd(TIM14, ENABLE);
	TIM_ITConfig(TIM14, TIM_IT_Update, ENABLE);
	nvic_config(TIM8_TRG_COM_TIM14_IRQn, 5);
}
Beispiel #10
0
//TIM6挂在APB1,输入时钟为42*2=84MHz
void TIM6_init(uint32_t period, uint16_t prescaler)
{
	TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
	
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE);
	
	TIM_TimeBaseStructure.TIM_Period = period-1;    
    TIM_TimeBaseStructure.TIM_Prescaler = prescaler-1;                
    TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;             
    TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
    TIM_TimeBaseInit(TIM6, &TIM_TimeBaseStructure);  
    TIM_Cmd (TIM6, ENABLE);
	TIM_ITConfig(TIM6, TIM_IT_Update, ENABLE);
	nvic_config(TIM6_DAC_IRQn, 1);	//优先级暂定为1
}
Beispiel #11
0
void uart4_init(uint32_t baudRate)
{
	USART_InitTypeDef USART_InitStructure;
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE);
	
	GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_UART4);
    GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_UART4);
	gpio_af_pp_up_init(GPIOC, GPIO_Pin_10|GPIO_Pin_11);
	
	USART_InitStructure.USART_BaudRate = baudRate;
	USART_InitStructure.USART_WordLength = USART_WordLength_8b;
	USART_InitStructure.USART_StopBits = USART_StopBits_1;
	USART_InitStructure.USART_Parity = USART_Parity_No;
	USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
	USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
	USART_Init(UART4, &USART_InitStructure); 
	USART_ITConfig(UART4, USART_IT_RXNE,ENABLE);
	USART_Cmd(UART4, ENABLE);
	USART_ClearFlag(UART4, USART_FLAG_TC);
	
	nvic_config(UART4_IRQn, 4);
}
Beispiel #12
0
/*!
    \brief      main routine will construct a MSC device
    \param[in]  none
    \param[out] none
    \retval     none
*/
int main(void)
{
    /* system clocks configuration */
    rcu_config();

    /* GPIO configuration */
    gpio_config();

    /* USB device configuration */
    usbd_core_init(&usb_device_dev);

    /* NVIC configuration */
    nvic_config();

    /* enabled USB pull-up */
    gpio_bit_set(USB_PULLUP, USB_PULLUP_PIN);

    /* now the usb device is connected */
    usb_device_dev.status = USBD_CONNECTED;

    while(usb_device_dev.status != USBD_CONFIGURED);

    while (1){}
}
void exti_config(GPIO_TypeDef *gpiox, u8 pin_num)
{
	EXTI_InitTypeDef EXTI_InitStructure;
	u8 exti_port_source_gpio;
	u32 pin_line = 0x00000001<<pin_num;
	uint8_t irq_channel;
	
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
	gpio_in_up_init(gpiox, pin_line);
	
	if(gpiox == GPIOA){
		exti_port_source_gpio = EXTI_PortSourceGPIOA;
	}
	else if(gpiox == GPIOB){
		exti_port_source_gpio = EXTI_PortSourceGPIOB;
	}
	else if(gpiox == GPIOC){
		exti_port_source_gpio = EXTI_PortSourceGPIOC;
	}
	else if(gpiox == GPIOD){
		exti_port_source_gpio = EXTI_PortSourceGPIOD;
	}
	else if(gpiox == GPIOE){
		exti_port_source_gpio = EXTI_PortSourceGPIOE;
	}
	else if(gpiox == GPIOF){
		exti_port_source_gpio = EXTI_PortSourceGPIOF;
	}
	else if(gpiox == GPIOG){
		exti_port_source_gpio = EXTI_PortSourceGPIOG;
	}
	else if(gpiox == GPIOH){
		exti_port_source_gpio = EXTI_PortSourceGPIOH;
	}
	else if(gpiox == GPIOI){
		exti_port_source_gpio = EXTI_PortSourceGPIOI;
	}
	else if(gpiox == GPIOJ){
		exti_port_source_gpio = EXTI_PortSourceGPIOJ;
	}
	else if(gpiox == GPIOK){
		exti_port_source_gpio = EXTI_PortSourceGPIOK;
	}
	else{
		printf("GPIO Port is not supported!\r\n");
		while(1);
	}
	
	SYSCFG_EXTILineConfig(exti_port_source_gpio, pin_num);
	
	EXTI_InitStructure.EXTI_Line = pin_line;
	EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
	EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
	EXTI_InitStructure.EXTI_LineCmd = ENABLE;
	EXTI_Init(&EXTI_InitStructure);
	
	if(pin_num >= 10){
		irq_channel = EXTI15_10_IRQn;
	}
	else if(pin_num >= 5){
		irq_channel = EXTI9_5_IRQn;
	}
	else {
		irq_channel = pin_num + 6;
	}
	
	nvic_config(irq_channel, 10);
}