Exemplo n.º 1
0
static void Motor_Output_Config(void)
{

	GPIO_InitTypeDef GPIO_InitStructure;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

	for(int i=0; i<NUM_MOTORS; i++) {

		RCC_GPIOClockCmd(Motor_En_Ports[i], ENABLE);
		GPIO_InitStructure.GPIO_Pin = Motor_En_Pins[i];
		GPIO_Init(Motor_En_Ports[i], &GPIO_InitStructure);
		GPIO_ResetBits(Motor_En_Ports[i], Motor_En_Pins[i]);
	}

	for(int i=0; i<NUM_MOTORS; i++) {
		RCC_GPIOClockCmd(Motor_Dir_Ports[i], ENABLE);
		GPIO_InitStructure.GPIO_Pin = Motor_Dir_Pins[i];
		GPIO_Init(Motor_Dir_Ports[i], &GPIO_InitStructure);

		RCC_GPIOClockCmd(Motor_Step_Ports[i], ENABLE);
		GPIO_InitStructure.GPIO_Pin = Motor_Step_Pins[i];
		GPIO_Init(Motor_Step_Ports[i], &GPIO_InitStructure);
		GPIO_ResetBits(Motor_Step_Ports[i], Motor_Step_Pins[i]);

		RCC_GPIOClockCmd(Motor_OE_Ports[i], ENABLE);
		GPIO_InitStructure.GPIO_Pin = Motor_OE_Pins[i];
		GPIO_Init(Motor_OE_Ports[i], &GPIO_InitStructure);
		GPIO_SetBits(Motor_OE_Ports[i], Motor_OE_Pins[i]);
	}

}
Exemplo n.º 2
0
void LimitSwitch_Config(void)
{
	GPIO_InitTypeDef GPIO_InitStructure;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

	RCC_GPIOClockCmd(X_Axis_Min_Port, ENABLE);
	GPIO_InitStructure.GPIO_Pin = X_Axis_Min_Pin;
	GPIO_Init(X_Axis_Min_Port, &GPIO_InitStructure);

	RCC_GPIOClockCmd(Y_Axis_Min_Port, ENABLE);
	GPIO_InitStructure.GPIO_Pin = Y_Axis_Min_Pin;
	GPIO_Init(Y_Axis_Min_Port, &GPIO_InitStructure);
	
	RCC_GPIOClockCmd(Z_Axis_Min_Port, ENABLE);
	GPIO_InitStructure.GPIO_Pin = Z_Axis_Min_Pin;
	GPIO_Init(Z_Axis_Min_Port, &GPIO_InitStructure);

	for (int i = 0; i < NUM_SWITCHS; ++i)
	{
		bSwitchPressed[i] = LimitSwitch_Pressed(i);
		lastInterrupt[i] = 0;
		bEventSent[i] = 0;
	}

	//不使用中断
	// limitSwitch_ExtiConfig();
}
Exemplo n.º 3
0
/*
 * 初始化串口配置
 */
void USARTx_Config(USART_TypeDef* USARTx, u32 USART_BaudRate)
{
    GPIO_InitTypeDef GPIO_InitStructure;
    USART_InitTypeDef USART_InitStructure;
    GPIO_TypeDef *USART_GPIO;
    u16 USART_Rx, USART_Tx;

    switch((u32)USARTx) {
        case (u32)USART1:
            USART_GPIO = GPIOA;
            USART_Tx = GPIO_Pin_9;
            USART_Rx = GPIO_Pin_10;
            break;
        case (u32)USART2:
            USART_GPIO = GPIOA;
            USART_Tx = GPIO_Pin_2;
            USART_Rx = GPIO_Pin_3;
            break;
        case (u32)USART3:
            USART_GPIO = GPIOB;
            USART_Tx = GPIO_Pin_10;
            USART_Rx = GPIO_Pin_11;
            break;

        default:
            return;
    }

    /* config USART clock */
    RCC_USARTClockCmd(USARTx, ENABLE);

    /* USART GPIO config */
    RCC_GPIOClockCmd(USART_GPIO, ENABLE);
    /* Configure USART Tx as alternate function push-pull */
    GPIO_InitStructure.GPIO_Pin = USART_Tx;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(USART_GPIO, &GPIO_InitStructure);
    /* Configure USART Rx as input*/
    GPIO_InitStructure.GPIO_Pin = USART_Rx;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
    GPIO_Init(USART_GPIO, &GPIO_InitStructure);

    /* USART mode config */
    USART_InitStructure.USART_BaudRate = USART_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(USARTx, &USART_InitStructure);
    USART_Cmd(USARTx, ENABLE);
}
Exemplo n.º 4
0
void USBDevice_Config()
{

    GPIO_InitTypeDef GPIO_InitStructure;
    RCC_GPIOClockCmd(USB_Port, ENABLE);

    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Pin = USB_Det;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;         /* 下拉输入 */
    GPIO_Init(USB_Port, &GPIO_InitStructure);

    USBCommon_Init();
}
Exemplo n.º 5
0
void DHT_Init(uint8_t type)
{
    _type = type;
    firstreading = true;

    RCC_GPIOClockCmd(DHT11_PORT, ENABLE);
    GPIO_InitStructure.GPIO_Pin = DHT11_PIN;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

    // set up the pins!
    DHT_pinMode(GPIO_Mode_IPU);
    _lastreadtime = 0;
}
Exemplo n.º 6
0
void ADC_Channel_Config(GPIO_TypeDef* GPIOx, uint16_t pin, uint8_t channel, uint8_t rank)
{
	GPIO_InitTypeDef GPIO_InitStructure;

	RCC_GPIOClockCmd(GPIOx, ENABLE);  //GPIO时钟

	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_InitStructure.GPIO_Pin = pin;

	GPIO_Init(GPIOx, &GPIO_InitStructure);

	ADC_RegularChannelConfig(ADC1, channel, rank, ADC_SampleTime_1Cycles5);
}
Exemplo n.º 7
0
void Fan_Config()
{
	GPIO_InitTypeDef GPIO_InitStructure;

	RCC_GPIOClockCmd(Ex1Fan_Port, ENABLE); 

	GPIO_InitStructure.GPIO_Pin =  Ex1Fan_Pin;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

	GPIO_Init(Ex1Fan_Port, &GPIO_InitStructure);
	Fan_Enable(false);

}
Exemplo n.º 8
0
/*
 * MAX6675引脚初始化
 */
void MAX6675_Config()
{
    GPIO_InitTypeDef GPIO_InitStructure;

    RCC_GPIOClockCmd(Thermcouple_Port, ENABLE);    //GPIO时钟

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;   //口线翻转速度为50MHz
    GPIO_InitStructure.GPIO_Pin = ThermcoupleSck_Pin | ThermcoupleCs_Pin;

    GPIO_Init(Thermcouple_Port, &GPIO_InitStructure);

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    GPIO_InitStructure.GPIO_Pin = ThermcoupleDo_Pin;

    GPIO_Init(Thermcouple_Port, &GPIO_InitStructure);
}
Exemplo n.º 9
0
void USBDevice_Config()
{

    GPIO_InitTypeDef GPIO_InitStructure;
    RCC_GPIOClockCmd(USB_Port, ENABLE);

    GPIO_InitStructure.GPIO_Pin = USB_Conn;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;      /* 开漏输出 */
    GPIO_Init(USB_Port, &GPIO_InitStructure);
    GPIO_SetBits(USB_Port, USB_Conn);

    GPIO_InitStructure.GPIO_Pin = USB_Det;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;         /* 下拉输入 */
    GPIO_Init(USB_Port, &GPIO_InitStructure);

    Set_USBClock();
}
Exemplo n.º 10
0
static void TIM2_Output_Config(bool bConnectToPWM, uint16_t pins) 
{
	GPIO_InitTypeDef GPIO_InitStructure;

	RCC_GPIOClockCmd(PWM2_Port, ENABLE); 

	GPIO_InitStructure.GPIO_Pin = pins;
	if(bConnectToPWM)
		GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
	else
		GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

	GPIO_Init(PWM2_Port, &GPIO_InitStructure);
	if(!bConnectToPWM){
#ifdef DRIVER_BOARD_POLARITY
		GPIO_SetBits(PWM2_Port, GPIO_InitStructure.GPIO_Pin);
#else
		GPIO_ResetBits(PWM2_Port, GPIO_InitStructure.GPIO_Pin);
#endif
	}
}